heap

package
v0.0.0-...-fa3f174 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyHeap = errors.New("empty heap")

Functions

This section is empty.

Types

type Heap

type Heap[T any, C comparator.Comparator[T]] struct {
	vector.Vector[T]
	// contains filtered or unexported fields
}

func New

func New[T any, C comparator.Comparator[T]]() Heap[T, C]

func NewWithCapacity

func NewWithCapacity[T any, C comparator.Comparator[T]](capacity int) Heap[T, C]

func (*Heap[T, C]) BubbleUp

func (h *Heap[T, C]) BubbleUp(i int)

BubbleUp bubbles the element at i up to its correct position

func (Heap[T, C]) Get

func (h Heap[T, C]) Get(i int) T

func (*Heap[T, C]) Heapify

func (h *Heap[T, C]) Heapify(i int)

Heapify fixes the subtree rooted at i

func (*Heap[T, C]) Pop

func (h *Heap[T, C]) Pop() error

func (*Heap[T, C]) Push

func (h *Heap[T, C]) Push(x T)

func (*Heap[T, C]) Set

func (h *Heap[T, C]) Set(i int, x T)

func (Heap[T, C]) Top

func (h Heap[T, C]) Top() (val T, err error)

type MaxHeap

type MaxHeap[T cmp.Ordered] struct {
	Heap[T, comparator.Greater[T]]
}

func NewMaxHeap

func NewMaxHeap[T cmp.Ordered]() MaxHeap[T]

type MinHeap

type MinHeap[T cmp.Ordered] struct {
	Heap[T, comparator.Less[T]]
}

func NewMinHeap

func NewMinHeap[T cmp.Ordered]() MinHeap[T]

Jump to

Keyboard shortcuts

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