Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BoundedMaxHeap ¶
type BoundedMaxHeap[T any] struct { // contains filtered or unexported fields }
BoundedMaxHeap represents a data structure with limited capacity that stores the top elements according to comparator
func NewBoundedMaxHeap ¶
func NewBoundedMaxHeap[T any](capacity int, comparator func(a, b T) int) *BoundedMaxHeap[T]
NewBoundedMaxHeap creates a new BoundedMaxHeap with the given capacity and comparator
func (*BoundedMaxHeap[T]) Add ¶
func (h *BoundedMaxHeap[T]) Add(element T)
Add inserts an element into the heap. If the heap exceeds its capacity, it removes the largest element.
func (*BoundedMaxHeap[T]) PopAllSorted ¶
func (h *BoundedMaxHeap[T]) PopAllSorted() []T
PopAllSorted removes all elements from the heap and returns them in sorted order (according to comparator).
Click to show internal directories.
Click to hide internal directories.