The default comparator for the heap actions. It is defined this way to be
consistent with the
Array.prototype.sort()
function.
"Sorts" an array in-place into a min-heap according to the passed comparator.
Removes and returns the minimum element from the heap while maintaining the heap substructure.
Adds a new element to a heap while keeping the heap substructure (according to the comparator).
Pushes value
onto the heap, then pops to return the minimum element in the
heap.
This combined action runs faster than a push followed by a pop.
This may return the value that was to be added, leaving the heap unchanged.
If this is not the intended use, consider using heapreplace
.
Pops the minimum element from the heap and then pushes value
onto the heap.
Faster than a pop followed by a push.
The returned element may be larger than the value added. If this is not
desired, consider using heappushpop
instead.
Provides a wrapper for the heap methods in this module to set the compare method.
Useful for defining a max-heap, or a heap that compares numbers by their value instead of their string representation.
This functionality can be obtained by instead explicitly stating the custom compare method every time, but that can become quite verbose, and cause bugs if omitted.
Generated using TypeDoc
A Function to compare two values of the same type
T
.The return value should be a number, v, such that
a
is less than valueb
, v is negative.a
is greater than valueb
, v is positive.a
is equal to valueb
, v is zero.