Documentation
¶
Overview ¶
Package mmheap provides a drop-in replacement for the container/heap package that provides min-max heap semantics.
The package interface is a superset of container/heap; any existing type that implements heap.Interface can be used with mmheap.
min-max heaps provide efficient inspection and removal of both the minimum and maximum elements. The data structure is described in detail here:
http://www.cs.otago.ac.nz/staffpriv/mike/Papers/MinMaxHeaps/MinMaxHeaps.pdf
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fix ¶
Fix re-establishes the heap ordering after the element at index i has changed its value.
Changing the value of the element at index i and then calling Fix is equivalent to, but less expensive than, calling Remove(h, i) followed by a Push of the new value.
func Init ¶
Init establishes the heap invariants required by the other routines in this package.
Init is idempotent with respect to the heap invariants and may be called whenever the heap invariants may have been invalidated.
func Max ¶
Max returns index of the maximum element in h.
Unlike the minimum element, which is the root node at index 0, the maximum element may be either the left-hand or right-hand child of the root node.
If h is empty it returns -1.
The complexity is O(1).
Types ¶
This section is empty.