SealedCreates a queue in natural order holding the elements of elements; empty when elements is
omitted, undefined or null.
Time: O(m) for m elements, with at most 2m comparisons.
Optionalelements: Iterable<E, any, any> | null
The initial elements. The comparator of a PriorityQueue given here is not
used; pass it as an option, or call copy().
Creates an empty queue with the given options.
Time: O(1).
The options; comparator is read once.
Creates a queue holding the elements of elements (empty when undefined or null), ordered
by options.comparator, or by natural order when it is omitted.
Time: O(m) for m elements, with at most 2m comparisons.
The initial elements.
Optionaloptions: PriorityQueueOptions<E>
The options; comparator is read once.
Marks collections so isCollection recognises them across copies of the package. Its key is
not exported, so the getter is not called directly. Time: O(1).
Marks instances of this class so instanceof recognises them across copies of the package.
Its key is not exported, so the getter is not called directly. Time: O(1).
Marks queues so isQueue recognises them across copies of the package. Its key is not
exported, so the getter is not called directly. Time: O(1).
'PriorityQueue', for Object.prototype.toString. Time: O(1).
A number that changes on every change to the contents and never on a read. Its exact values are unspecified. Time: O(1).
The number of elements. Time: O(1).
The value-equality protocol; delegates to equals (identity). Time: O(1).
The value-equality protocol: an identity hash, unspecified in value. Time: O(1).
Node's inspect hook: PriorityQueue(2) [ 1, 2 ] in console.log. Time: as toString.
Returns an iterator over the elements in heap order, which is not sorted.
Time: O(1) to create; O(1) per step.
A new iterator.
Adds element and returns the queue, so calls chain. On an error nothing is added.
Time: O(log n), with at most ⌊log2 n⌋ + 1 comparisons, where n is the size after the add.
The element to add.
The queue.
Adds every element of elements, one at a time, after reading them all and checking that none
is null or undefined (if one is, nothing is added). If a comparison fails part-way, the
elements added before it stay.
Time: O(m log(n + m)) for m elements.
The elements to add.
true when any element was added.
Returns the comparator given at construction, or undefined when the queue uses natural
order.
Time: O(1).
The comparator, or undefined.
Returns a new PriorityQueue with the same elements and the same comparator, independent of
this one (the elements themselves are not copied). The comparator is not called.
Time: O(n).
The copy.
Returns a cursor over the elements in heap order; remove() removes the element next()
returned, and the cursor still visits every other element exactly once.
Time: O(1) to create; next O(1); remove O(log n), or O(n) for an element the removal of
another moved behind the cursor.
A new cursor.
Removes one element equal to element under SameValueZero (not under the comparator: two
elements that compare as equal are still different elements). On an error nothing is removed.
Time: O(n) to find it, then at most 2⌊log2 n⌋ + 1 comparisons.
The value to remove.
true when an element was removed.
Returns whether other is this queue. Queues compare by identity. Called through a Proxy
of the queue, it is true for that proxy too; the queue itself does not know its proxies, so
queue.equals(proxy) is false.
Time: O(1).
Any value.
true when other is this queue.
Calls action(element) for each element in heap order, which is not sorted, with this set to
thisArg.
Time: O(n) plus the calls.
Called with each element.
OptionalthisArg: unknown
The this value for action.
Returns whether some element is equal to element under SameValueZero (not under the
comparator); always false for null and undefined.
Time: O(n).
The value to look for.
true when present.
Returns the least element, the one poll() returns next, without removing it, or undefined
when the queue is empty. The comparator is not called.
Time: O(1).
The least element, or undefined.
Removes and returns the least element, or returns undefined when the queue is empty. On an
error nothing is removed.
Time: O(log n), with at most 2⌊log2 n⌋ comparisons.
The removed element, or undefined.
Removes every element equal to one in elements (SameValueZero). Decides first, then rebuilds
the heap from the remaining elements; an error while deciding or rebuilding removes nothing.
Time: O(n + m) for m elements, plus at most 2n comparisons; O(n) extra memory.
The elements to remove.
true when any element was removed.
Calls predicate(element) on every element, then removes those for which it returned a truthy
value and rebuilds the heap; an error from predicate or the comparator removes nothing.
Time: O(n) plus the calls, plus at most 2n comparisons; O(n) extra memory.
Called with each element.
true when any element was removed.
Removes every element not equal to one in elements (SameValueZero). Decides first, then
rebuilds the heap from the remaining elements; an error while deciding or rebuilding removes
nothing.
Time: O(n + m) for m elements, plus at most 2n comparisons; O(n) extra memory.
The elements to keep.
true when any element was removed.
Returns a new array of the elements in heap order, which is not sorted.
Time: O(n).
A new array.
Returns a new array of the elements in heap order, so JSON.stringify writes the queue as an
array.
Time: O(n).
A new array.
Static[hasReturns whether value is a PriorityQueue, including one created by another copy of the
library with the same major version.
Time: O(1).
The value on the left of instanceof.
true when value is a PriorityQueue.
StaticfromReturns a new queue of the elements of elements, ordered by options.comparator, or by
natural order when it is omitted. The comparator of a PriorityQueue given as elements is
not used.
Time: O(m) for m elements, with at most 2m comparisons.
The elements.
Optionaloptions: PriorityQueueOptions<T>
The options; comparator is read once.
A new queue.
A queue that always hands out its least element next, stored as a binary heap:
addandpollcost O(log n) andpeekO(1). The order is the natural order of the elements, or thecomparatoroption.Iteration,
toArray,toJSONandtoStringvisit the elements in heap order, which is not sorted; take them out withpollin a loop for sorted output. Which of several equal elements is polled first is unspecified.nullandundefinedare not allowed as elements, sopoll()andpeek()returningundefinedalways means the queue is empty. A comparator that throws or returnsNaNleaves the queue as it was. Two queues are equal only when they are the same object. Adding or removing while iterating throwsConcurrentModificationError; use a cursor to remove while iterating.The class is not designed to be subclassed.
Example