mirror of
https://github.com/luxfi/explorer-v1.git
synced 2026-10-30 19:34:59 +00:00
0161e7ae90
* chore(deps-dev): bump eslint in /apps/block_scout_web/assets Bumps [eslint](https://github.com/eslint/eslint) from 8.57.1 to 9.19.0. - [Release notes](https://github.com/eslint/eslint/releases) - [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md) - [Commits](https://github.com/eslint/eslint/compare/v8.57.1...v9.19.0) --- updated-dependencies: - dependency-name: eslint dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> * Finalize eslint update * Eslint 9.19 -> 9.21 --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
73 lines
1.6 KiB
JavaScript
73 lines
1.6 KiB
JavaScript
/*
|
|
|
|
Queue.js
|
|
|
|
A function to represent a queue
|
|
|
|
Created by Kate Morley - http://code.iamkate.com/ - and released under the terms
|
|
of the CC0 1.0 Universal legal code:
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/legalcode
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Creates a new queue. A queue is a first-in-first-out (FIFO) data structure -
|
|
* items are added to the end of the queue and removed from the front.
|
|
*/
|
|
export default function Queue(){
|
|
|
|
// initialize the queue and offset
|
|
var queue = [];
|
|
var offset = 0;
|
|
|
|
// Returns the length of the queue.
|
|
this.getLength = function(){
|
|
return (queue.length - offset);
|
|
}
|
|
|
|
// Returns true if the queue is empty, and false otherwise.
|
|
this.isEmpty = function(){
|
|
return (queue.length == 0);
|
|
}
|
|
|
|
/* Enqueues the specified item. The parameter is:
|
|
*
|
|
* item - the item to enqueue
|
|
*/
|
|
this.enqueue = function(item){
|
|
queue.push(item);
|
|
}
|
|
|
|
/* Dequeues an item and returns it. If the queue is empty, the value
|
|
* 'undefined' is returned.
|
|
*/
|
|
this.dequeue = function(){
|
|
|
|
// if the queue is empty, return immediately
|
|
if (queue.length == 0) return undefined;
|
|
|
|
// store the item at the front of the queue
|
|
var item = queue[offset];
|
|
|
|
// increment the offset and remove the free space if necessary
|
|
if (++ offset * 2 >= queue.length){
|
|
queue = queue.slice(offset);
|
|
offset = 0;
|
|
}
|
|
|
|
// return the dequeued item
|
|
return item;
|
|
|
|
}
|
|
|
|
/* Returns the item at the front of the queue (without dequeuing it). If the
|
|
* queue is empty then undefined is returned.
|
|
*/
|
|
this.peek = function(){
|
|
return (queue.length > 0 ? queue[offset] : undefined);
|
|
}
|
|
|
|
}
|