heap

package
v0.0.0-...-1ed95e1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2025 License: LGPL-3.0 Imports: 3 Imported by: 0

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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL