PriorityQueue<T> Class

A priority queue implemented as a heap array. The queue is ordered by an OrderedComparator function supplied by the user such that the value in the queue that compares less than all other values is always located at the front of the queue.


  • Iterable<T>


Name Description
constructor<T>(compare: OrderedComparator<T>, clone: CloneFunction<T>shallowClone): PriorityQueue<T> Constructor  
[iterator](): Iterator<T, any, undefined> Returns an iterator over the contents of the heap suitable for use in for-of loops.  
_heapify(index: number): void Protected    
_peek(index: number): undefined | T Protected Returns the value at the specified index in the queue.  
_pop(index: number): undefined | T Protected Removes the value at the specified index from the queue and reorders the queue.  
_swap(a: number, b: number): void Protected    
append(value: T): T Pushes a value onto the back of the queue without making any attempt to enforce ordering.  
clear(): void Removes all values from the queue.  
pop(): undefined | T Removes the front-most element off of the queue and returns it.  
push(value: T): T Pushes a value onto the queue according to the sorting criterion.  
sort(): void Reorders the queue.  


Name Type Description
_array Protected T[]    
_clone Protected Readonly CloneFunction<T>    
_compare Protected Readonly OrderedComparator<T>    
front Accessor ReadOnly undefined | T Returns the element at the front of the queue, or undefined if the queue is empty.  
isEmpty Accessor ReadOnly boolean Returns true if the queue contains no values.  
length Accessor ReadOnly number The number of values in the queue.  

Defined in

Last Updated: 25 May, 2024