Object buckets.Queue

A queue is a First-In-First-Out (FIFO) data structure, the first element added to the queue will be the first one to be removed. This implementation uses a linked list as the underlying storage.

Object Summary
Constructor Name and Description
Creates an empty queue.
Method Summary
Method Name and Description
buckets.Queue.add(elem)
Inserts the specified element into the end of the queue.
buckets.Queue.clear()
Removes all the elements from the queue.
buckets.Queue.contains(elem, equalsFunction)
Returns true if the queue contains the specified element.
buckets.Queue.dequeue()
Retrieves and removes the head of the queue.
buckets.Queue.enqueue(elem)
Inserts the specified element into the end of the queue.
buckets.Queue.equals(other, equalsFunction)
Returns true if the queue is equal to another queue.
buckets.Queue.forEach(callback)
Executes the provided function once per each element present in the queue in FIFO order.
buckets.Queue.isEmpty()
Checks if the queue is empty.
buckets.Queue.peek()
Retrieves, but does not remove, the head of the queue.
buckets.Queue.size()
Returns the number of elements in the queue.
buckets.Queue.toArray()
Returns an array containing all the elements in the queue in FIFO order.
Object Detail
buckets.Queue()
Creates an empty queue.
Method Detail
<static> {boolean} buckets.Queue.add(elem)
Inserts the specified element into the end of the queue. Equivalent to enqueue.
Parameters:
{Object} elem
The element to insert.
Returns:
{boolean} True if the element was inserted, or false if it's undefined.

<static> buckets.Queue.clear()
Removes all the elements from the queue.

<static> {boolean} buckets.Queue.contains(elem, equalsFunction)
Returns true if the queue contains the specified element.

If the elements inside the queue are not comparable with the === operator, a custom equals function should be provided to perform searches, the function must receive two arguments and return true if they are equal, false otherwise. Example:

var petsAreEqualByName = function(pet1, pet2) {
 return pet1.name === pet2.name;
}
Parameters:
{Object} elem
Element to search for.
{function(Object|Object):boolean=} equalsFunction
Optional function to check if two elements are equal.
Returns:
{boolean} True if the queue contains the specified element, false otherwise.

<static> {*} buckets.Queue.dequeue()
Retrieves and removes the head of the queue.
Returns:
{*} The head of the queue, or undefined if the queue is empty.

<static> {boolean} buckets.Queue.enqueue(elem)
Inserts the specified element into the end of the queue.
Parameters:
{Object} elem
The element to insert.
Returns:
{boolean} True if the element was inserted, or false if it's undefined.

<static> {boolean} buckets.Queue.equals(other, equalsFunction)
Returns true if the queue is equal to another queue. Two queues are equal if they have the same elements in the same order.
Parameters:
{buckets.Queue} other
The other queue.
{function(Object|Object):boolean=} equalsFunction
Optional function to check if two elements are equal. If the elements in the queues are custom objects you should provide a custom equals function, otherwise the === operator is used to check equality between elements.
Returns:
{boolean} True if the queue is equal to the given queue.

<static> buckets.Queue.forEach(callback)
Executes the provided function once per each element present in the queue in FIFO order.
Parameters:
{function(Object):*} callback
Function to execute, it's invoked an element as argument, to break the iteration you can optionally return false inside the callback.

<static> {boolean} buckets.Queue.isEmpty()
Checks if the queue is empty.
Returns:
{boolean} True if and only if the queue contains no items.

<static> {*} buckets.Queue.peek()
Retrieves, but does not remove, the head of the queue.
Returns:
{*} The head of the queue, or undefined if the queue is empty.

<static> {number} buckets.Queue.size()
Returns the number of elements in the queue.
Returns:
{number} The number of elements in the queue.

<static> {Array.<*>} buckets.Queue.toArray()
Returns an array containing all the elements in the queue in FIFO order.
Returns:
{Array.<*>} An array containing all the elements in the queue in FIFO order.