Documentation
¶
Overview ¶
Package heaps implements a generic heap data structure.
Index ¶
- func PriorityChannel[T any](inCh <-chan T, lessFunc func(T, T) bool) <-chan T
- type Heap
- func (h *Heap[T]) All() iter.Seq[T]
- func (h *Heap[T]) Cap() int
- func (h *Heap[T]) Clip() *Heap[T]
- func (h *Heap[T]) Empty() bool
- func (h *Heap[T]) Grow(n int) *Heap[T]
- func (h *Heap[T]) Len() int
- func (h *Heap[T]) MustPop() T
- func (h *Heap[T]) Peek() (T, bool)
- func (h *Heap[T]) Pop() (T, bool)
- func (h *Heap[T]) PopAll() []T
- func (h *Heap[T]) Push(value T) *Heap[T]
- func (h *Heap[T]) PushMany(values ...T) *Heap[T]
- func (h *Heap[T]) PushPop(value T) T
- func (h *Heap[T]) Set(values []T) *Heap[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PriorityChannel ¶
PriorityChannel greedily reads values from inCh and returns a channel that returns the same values prioritized according to lessFunc, with lesser values returned first. When inCh is closed, all remaining values are written to the returned channel, and then the returned channel is closed.
Types ¶
type Heap ¶
type Heap[T any] struct { // contains filtered or unexported fields }
A Heap is a heap of Ts.
func NewOrderedHeap ¶
NewOrderedHeap returns a new heap that operates on cmp.Ordered elements.
func NewReverseOrderedHeap ¶
NewReverseOrderedHeap returns a new heap that operates on cmp.Ordered elements in reverse order.
func (*Heap[T]) MustPop ¶
func (h *Heap[T]) MustPop() T
MustPop returns the lowest value in h. It panics if h is empty.
func (*Heap[T]) Peek ¶
Peek returns the lowest value in h in O(1) time and memory, without removing it, and whether it exists.
func (*Heap[T]) Pop ¶
Pop returns the lowest value in h, removing it, and whether it exists in O(N) time and O(1) memory.