-
Notifications
You must be signed in to change notification settings - Fork 0
Docs
Here it is the whole documentation of Q. These methods are pretty self explanatory, but, well, a little bit more info wouldn't hurt anyone.
The queue is implemented to shrink it's size when the collection size is 10% smaller than the array size. Yo can tweek these value in the source code to match your needs.
...
if(l < q.length*0.9){
//Remove unnecessary and empty elements
q = q.slice(0,l);
}
...
The library only has one constructor. Simple and quick.
Creates a Q instance with an empty queue and of size 0.
var q = Q();
The class has only 2 private fields
An array that contains the whole collection.
Integer that holds the offset value of the queue.
The enqueue method takes a generic element and puts it in the queue.
q.enqueue('example');
q.enqueue(2);
q.enqueue(new Date());
q.enqueue([1,2,3]);
The dequeue method returns the first element enqueued and removes it from the collection
var item = q.dequeue();
var item2 = q.dequeue();
if(item == item2){
alert('true');
}else{
//These part of the block will be triggered
alert('false');
}
Returns the first enqueued element of the collection.
var item = q.peek();
var item2 = q.peek();
if(item == item2){
//These part of the block will be triggered
alert('true');
}else{
alert('false');
}
If the queue is empety returns true, otherwise returns false.
...
if(q.isEmpty()){
...
Returns the real size of the collection (not the size of the array)
...
if(q.size() < 5)
...
for(var j = 0; j < q.size(); j++)
...