heap

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

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

Go to latest
Published: Jan 6, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Heap

type Heap[K cmp.Ordered, T comparable] struct {
	// contains filtered or unexported fields
}

Heap is a generic min-heap implementation that allows efficient access to elements by their data value.

func NewHeap

func NewHeap[K cmp.Ordered, T comparable]() *Heap[K, T]

NewHeap creates a new empty heap.

func (*Heap[K, T]) Len

func (h *Heap[K, T]) Len() int

Len returns the number of items in the heap.

func (*Heap[K, T]) Peek

func (h *Heap[K, T]) Peek() (k K, v T, ok bool)

Peek returns the item with the smallest key without removing it. Returns zero values and false if the heap is empty.

func (*Heap[K, T]) Pop

func (h *Heap[K, T]) Pop() (k K, v T, ok bool)

Pop removes and returns the item with the smallest key from the heap. Returns zero values and false if the heap is empty.

func (*Heap[K, T]) Push

func (h *Heap[K, T]) Push(key K, data T)

Push adds an item to the heap with the given key and data.

func (*Heap[K, T]) Remove

func (h *Heap[K, T]) Remove(data T) bool

Remove removes the item with the given data value if it exists. Returns true if an item was removed, false if not found.

Jump to

Keyboard shortcuts

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