FIFO Data structure
Extends Instance Properties| Property | Type | Default Value | Description |
| count | Number | the current number of elements in this queue | |
| isEmpty | Boolean | true if this queue is empty | |
| values | Array | a copy of the values contained in this queue | |
Removes all items from this queue
Source
function (){
this.__queue.length = 0;
this.__next = 0;
this.__last = 0;
}
Determine if this queue contains the element
Argumentsthe object to find
Boolean true if this queue contains the element
function (obj){
return this.__queue.indexOf(obj) !== -1;
}
Removes first item from the head of the queue
Returns* The element removed from this queue. Returns undefined if the queue is empty.
function (){
var next = this.__next,
ret,
queue;
if (next !== this.__last) {
queue = this.__queue;
ret = queue[next];
queue[this.__next++] = undefined;
}
return ret;
}
Add data to this queue
Argumentselement to add
function (data){
this.__queue[this.__last++] = data;
}
Retrieves the item at the head of the queue without removing it
Returns* The element at the head of the queue. Returns undefined if the queue is empty.
function (){
var next = this.__next,
ret;
if (next !== this.__last) {
ret = this.__queue[next];
}
return ret;
}
Removes an element from this queue.
Argumentsthe data to remove.
Boolean true if the element was removed, false otherwise.
function (obj){
var index = this.__queue.indexOf(obj), ret = false;
if (index !== -1) {
if (index === this.__next) {
this.dequeue();
} else {
this.__queue.splice(index, 1);
this.__last--;
}
ret = true;
}
return ret;
}
MIT https://github.com/C2FO/comb/raw/master/LICENSE
git clone git://github.com/C2FO/comb.git