package
Version:
v0.0.0-...-157c9c8
Opens a new window with list of versions in this module.
Published: Apr 26, 2024
License: GPL-3.0
Opens a new window with license information.
Imports: 1
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
Documentation
¶
type Heap[T any] struct {
Data []T
Less func(i, j int) bool
}
Heap keeps data sorted with O(log n) for Push and Pop.
NewMax creates a max heap. Pop will return the highest value.
NewMin creates a min heap. Pop will return the lowest value.
func (h *Heap[T]) Pop() T
Pop a value from the heap. This will return the "Least" value according to
the Less func.
func (h *Heap[T]) Push(v T)
Push a value onto the heap.
func (h *Heap[T]) SetLess(less func(i, j T) bool)
SetLess using a function to compare the types directly instead of comparing
based in indice.
Sort a heap using Less. Useful when initilizing a heap.
Ordered data types can be used with NewMin and NewMax without the need to
define the Less func on the Heap.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.