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
  1. function (){
  2. this.__queue.length = 0;
  3. this.__next = 0;
  4. this.__last = 0;
  5. }

contains Function Public


Defined collections/Queue.js

Determine if this queue contains the element

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

dequeue Function Public


Defined collections/Queue.js

Removes first item from the head of the queue

Returns Source
  1. function (){
  2. var next = this.__next,
  3. ret,
  4. queue;
  5. if (next !== this.__last) {
  6. queue = this.__queue;
  7. ret = queue[next];
  8. queue[this.__next++] = undefined;
  9. }
  10. return ret;
  11. }

enqueue Function Public


Defined collections/Queue.js

Add data to this queue

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

peek Function Public


Defined collections/Queue.js

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

Returns Source
  1. function (){
  2. var next = this.__next,
  3. ret;
  4. if (next !== this.__last) {
  5. ret = this.__queue[next];
  6. }
  7. return ret;
  8. }

remove Function Public


Defined collections/Queue.js

Removes an element from this queue.

Arguments Returns Source
  1. function (obj){
  2. var index = this.__queue.indexOf(obj), ret = false;
  3. if (index !== -1) {
  4. if (index === this.__next) {
  5. this.dequeue();
  6. } else {
  7. this.__queue.splice(index, 1);
  8. this.__last--;
  9. }
  10. ret = true;
  11. }
  12. return ret;
  13. }

License

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

Meta