The function used to compare two elements. It is determinant for the heap structure. By default, it compares numbers so it must be replaced with a custom function when storing another data type. It also allows to use a MinBinaryHeap
Replaces the current compare function with the provided
CompareFunction
. A compare function has the signature:
CompareFunction<T>(a: T, b: T) => -1 | 0 | 1
.
To keep its integrity, the tree is fully rebuilt.
The function to use to compare two values.
The tree instance.
Generated using TypeDoc
Implementation of a Binary Heap that behaves like a max binary heap with numeric values by default. Nevertheless, it can be provided a custom
CompareFunction
to store any type of data, or to use it as a min binary heap for instance.