Construct a new prioriry queue.
const q = new PriorityQueue<number>({
capacity: 1024,
compare: (a, b) => a < b,
elements: [1, 2, 3]
})
Count the amount of elements in the collection.
⚠️ In most cases, this should be an O(1)
operation. However, there are
cases where this can be an O(n)
operation. Therefore, it is recommended
to always cache the result in a local variable.
Returns an object which is able to sift through the values in this collection.
The order by which the elements are traversed depends on the kind of collection. For unordered collections, the iteration order is unspecified and may even differ between two iterations on the same collection.
Remove all elements from this collection, effectively setting the collection to the empty collection.
Copies all elements in the collection to a new one of the same kind.
Get the next element in the queue without removing it from the collection.
Get the next element in the order defined by the queue and remove it from the collection.
Converts the entire collection to a range.
Generated using TypeDoc
A queue that pops element based on their given priority.
The queue will return elements with a lower priority first. If you want the reverse, simply invert the function that is used to compare two elements.
The following table summarises the time complexity of the most commonly used properties.
Examples
Queue
Stack