Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BinaryHeap ¶
type BinaryHeap[T comparable] struct { // contains filtered or unexported fields }
BinaryHeap is the main heap type.
func New ¶
func New[T comparable](pred func(a T, b T) bool) BinaryHeap[T]
New is used to create a new heap. The passed function is a predicate that returns true if the first parameter is greater than the second. This predicate defines the sorting order between the heap items and is called during insertion and extraction.
func (BinaryHeap[T]) Contains ¶
func (b BinaryHeap[T]) Contains(val T) bool
Contains returns true if the value exists in the heap, false if not.
func (BinaryHeap[T]) Count ¶
func (b BinaryHeap[T]) Count() int
Count returns the amount of entries in the heap.
func (BinaryHeap[T]) Empty ¶
func (b BinaryHeap[T]) Empty() bool
Empty returns true if the heap is empty, false if not.
func (*BinaryHeap[T]) Extract ¶
func (b *BinaryHeap[T]) Extract() T
Extract returns and removes the first value from the heap.
func (BinaryHeap[T]) ForEach ¶
func (b BinaryHeap[T]) ForEach(f func(val T))
ForEach iterates over the dataset within the heap, calling the passed function for each value.
func (*BinaryHeap[T]) Insert ¶
func (b *BinaryHeap[T]) Insert(val T)
Insert inserts a new value into the heap.
func (BinaryHeap[T]) Peek ¶
func (b BinaryHeap[T]) Peek() T
Peek returns the first value at the top of the heap.