Object buckets.PriorityQueue

In a priority queue each element is associated with a "priority", elements are dequeued in highest-priority-first order (the elements with the highest priority are dequeued first). This implementation uses a binary heap as the underlying storage.

If the inserted elements are custom objects, a compare function must be provided, otherwise the <=, === and >= operators are used to compare object priority.

Example:

function compare(a, b) {
 if (a is less than b by some ordering criterion) {
    return -1;
 } if (a is greater than b by the ordering criterion) {
    return 1;
 }
 // a must be equal to b
 return 0;
}

Object Summary
Constructor Name and Description
buckets.PriorityQueue(compareFunction)
Creates an empty priority queue.
Method Summary
Method Name and Description
buckets.PriorityQueue.add(element)
Inserts the specified element into the priority queue.
buckets.PriorityQueue.clear()
Removes all elements from the priority queue.
buckets.PriorityQueue.contains(element)
Returns true if the priority queue contains the specified element.
buckets.PriorityQueue.dequeue()
Retrieves and removes the highest priority element of the queue.
buckets.PriorityQueue.enqueue(element)
Inserts the specified element into the priority queue.
buckets.PriorityQueue.equals(other)
Returns true if the queue is equal to another queue.
buckets.PriorityQueue.forEach(callback)
Executes the provided function once per element present in the queue in no particular order.
buckets.PriorityQueue.isEmpty()
Checks if the priority queue is empty.
buckets.PriorityQueue.peek()
Retrieves, but does not remove, the highest priority element of the queue.
buckets.PriorityQueue.size()
Returns the number of elements in the priority queue.
buckets.PriorityQueue.toArray()
Returns an array containing all the elements in the queue in no particular order.
Object Detail
buckets.PriorityQueue(compareFunction)
Creates an empty priority queue.
Parameters:
{function(Object|Object):number=} compareFunction
Optional function used to compare two element priorities. Must return a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
Method Detail
<static> {boolean} buckets.PriorityQueue.add(element)
Inserts the specified element into the priority queue. It's equivalent to enqueue.
Parameters:
{Object} element
The element to insert.
Returns:
{boolean} True if the element was inserted, or false if it's undefined.

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

<static> {boolean} buckets.PriorityQueue.contains(element)
Returns true if the priority queue contains the specified element.
Parameters:
{Object} element
Element to search for.
Returns:
{boolean} True if the priority queue contains the specified element, false otherwise.

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

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

<static> {boolean} buckets.PriorityQueue.equals(other)
Returns true if the queue is equal to another queue. Two priority queues are equal if they have the same elements.
Parameters:
{buckets.PriorityQueue} other
The other queue.
Returns:
{boolean} True if the queue is equal to the given queue.

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

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

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

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

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