Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Heap ¶
type Heap[E constraints.Ordered] []E
Heap implements a min-heap.
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 Remove(h, i) followed by a Push of the new value.
The complexity is O(log n) where n = h.Len().
func (*Heap[E]) Init ¶
func (h *Heap[E]) 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.
The complexity is O(n) where n = h.Len().
func (*Heap[E]) Pop ¶
func (h *Heap[E]) Pop() E
Pop removes and returns the minimum element (according to Less) from the heap. Pop is equivalent to Remove(h, 0).
The complexity is O(log n) where n = h.Len().
type HeapFunc ¶
HeapFunc implements a min-heap with custom comparison.
func (*HeapFunc[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 Remove(h, i) followed by a Push of the new value.
The complexity is O(log n) where n = h.Len().
func (*HeapFunc[E]) Init ¶
func (h *HeapFunc[E]) 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.
The complexity is O(n) where n = h.Len().
func (*HeapFunc[E]) Pop ¶
func (h *HeapFunc[E]) Pop() E
Pop removes and returns the minimum element (according to Less) from the heap. Pop is equivalent to Remove(h, 0).
The complexity is O(log n) where n = h.Len().
type RingBuffer ¶
type RingBuffer[E any] struct { // contains filtered or unexported fields }
func NewRingBuffer ¶
func NewRingBuffer[E any](b []E) *RingBuffer[E]
NewRingBuffer uses b as a ring buffer. The capacity of the buffer is cap(b) and b[:len(b)] are the initial contents. So make([]E, 0, N) is an empty buffer of size N.
func (*RingBuffer[E]) Cap ¶
func (b *RingBuffer[E]) Cap() int
Cap returns the capacity of the buffer.
func (*RingBuffer[E]) Len ¶
func (b *RingBuffer[E]) Len() int
Len returns the number of elements currently in the buffer.