Documentation ¶
Overview ¶
Package sliceheap implements a generic heap based on a slice. - https://github.com/golang/go/issues/47632 - https://gotipplay.golang.org/p/d4M0QBkfmIr
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Heap ¶
type Heap[E any] struct { // contains filtered or unexported fields }
A Heap is a min-heap backed by a slice.
func (*Heap[E]) 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 h.Remove(i) followed by a Push of the new value. The complexity is O(log n) where n = h.Len(). The index for use with Fix is recorded using the function passed to SetIndex.
func (*Heap[E]) Peek ¶
func (h *Heap[E]) Peek() E
Peek returns the minimum element (according to the less function) in the heap. Peek panics if the heap is empty. The complexity is O(1).
func (*Heap[E]) Pop ¶
func (h *Heap[E]) Pop() E
Pop removes and returns the minimum element (according to the less function) from the heap. Pop panics if the heap is empty. The complexity is O(log n) where n = h.Len().
func (*Heap[E]) Push ¶
func (h *Heap[E]) Push(elem E)
Push pushes an element onto the heap. The complexity is O(log n) where n = h.Len().