FIFO Data structure

Extends Instance Properties
PropertyTypeDefault ValueDescription
countNumber

the current number of elements in this queue

isEmptyBoolean

true if this queue is empty

valuesArray

a copy of the values contained in this queue

Constructor

Defined collections/Queue.js

clear Function Public


Defined collections/Queue.js

Removes all items from this queue

Source
function (){
   this.__queue.length = 0;
   this.__next = 0;
   this.__last = 0;
           
}
    

contains Function Public


Defined collections/Queue.js

Determine if this queue contains the element

Arguments Returns Source
function (obj){
   return this.__queue.indexOf(obj) !== -1;
           
}
    

dequeue Function Public


Defined collections/Queue.js

Removes first item from the head of the queue

Returns Source
function (){
   var next = this.__next,
       ret,
       queue;
   if (next !== this.__last) {
       queue = this.__queue;
       ret = queue[next];
       queue[this.__next++] = undefined;
   }
   return ret;
           
}
    

enqueue Function Public


Defined collections/Queue.js

Add data to this queue

Arguments Source
function (data){
   this.__queue[this.__last++] = data;
           
}
    

peek Function Public


Defined collections/Queue.js

Retrieves the item at the head of the queue without removing it

Returns Source
function (){
   var next = this.__next,
       ret;
   if (next !== this.__last) {
       ret = this.__queue[next];
   }
   return ret;
           
}
    

remove Function Public


Defined collections/Queue.js

Removes an element from this queue.

Arguments Returns Source
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;
           
}
    

License

MIT https://github.com/C2FO/comb/raw/master/LICENSE

Meta