The type of elements stored in the heap.
Gets the number of elements in the heap.
The number of elements in the heap.
Builds a heap from an array of items in O(n) time.
The array of items to build the heap from.
Removes all elements from the heap.
Checks if a value exists in the heap.
The value to check for.
True if the value exists in the heap, false otherwise.
Returns the highest priority element without removing it.
The highest priority element in the heap.
Removes and returns the highest priority element from the heap.
The highest priority element in the heap.
Rebalances an element in the heap after its value or comparison-affecting properties have changed.
The element to rebalance in the heap
True if the element was found and rebalanced, false otherwise.
Removes a specific element from the heap.
The element to remove.
True if the element was found and removed, false otherwise.
A generic binary heap implementation that supports efficient priority operations.
This data structure maintains elements in a partially ordered heap structure, enabling O(log n) push, pop, and remove operations. The ordering is determined by the provided comparison function.
Remarks
The type parameter
Tmust be suitable for use as a key in a JavaScriptMap:Tis a primitive (string,number,symbol), values are compared by value.Tis an object, values are compared by reference (object identity).Duplicate values (by reference or primitive value) are not supported; only the most recently added instance will be tracked.
Example usage: