Class Index | File Index

Classes


Class 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). Priority queues are implemented as heaps. If the inserted elements are custom objects a compare function must be provided, otherwise the <=, === and >= operators are used to compare object priority.

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;
}

Defined in: <../buckets.js>.

Class Summary
Constructor Attributes Constructor Name and Description
 
buckets.PriorityQueue(compareFunction)
Creates an empty priority queue.
Method Summary
Method Attributes Method Name and Description
 
add(element)
Inserts the specified element into this priority queue.
 
Removes all elements from this priority queue.
 
contains(element)
Returns true if this priority queue contains the specified element.
 
Retrieves and removes the highest priority element of this queue.
 
enqueue(element)
Inserts the specified element into this priority queue.
 
forEach(callback)
Executes the provided function once per element present in this queue in no particular order.
 
Checks if this priority queue is empty.
 
peek()
Retrieves, but does not remove, the highest priority element of this queue.
 
size()
Returns the number of elements in this priority queue.
Class 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
{boolean} add(element)
Inserts the specified element into this priority queue. It is equivalent to enqueue.
Parameters:
{Object} element
the element to insert.
Returns:
{boolean} True if the element was inserted, or false if it is undefined.

clear()
Removes all elements from this priority queue.

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

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

{boolean} enqueue(element)
Inserts the specified element into this priority queue.
Parameters:
{Object} element
The element to insert.
Returns:
{boolean} True if the element was inserted, or false if it is undefined.

forEach(callback)
Executes the provided function once per element present in this queue in no particular order.
Parameters:
{function(Object):*} callback
Function to execute, it is invoked with one argument: the element value, to break the iteration you can optionally return false inside the callback.

{boolean} isEmpty()
Checks if this priority queue is empty.
Returns:
{boolean} True if and only if this priority queue contains no items; false otherwise.

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

{number} size()
Returns the number of elements in this priority queue.
Returns:
{number} The number of elements in this priority queue.

Documentation generated by JsDoc Toolkit 2.4.0 on Thu Mar 12 2015 00:38:48 GMT-0500 (COT)