heap

package
v0.0.0-...-089553b Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0, Apache-2.0 Imports: 1 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Heap

type Heap[E any] struct {
	// contains filtered or unexported fields
}

A Heap is a min-heap backed by a slice.

func New

func New[E any](less func(E, E) bool, capacity int) *Heap[E]

New constructs a new Heap with a comparison function.

func (*Heap[E]) Len

func (h *Heap[E]) Len() int

Len returns the number of elements in the heap.

func (*Heap[E]) Peek

func (h *Heap[E]) Peek() E

Peek returns the minimum element (according to the less function) in the heap. Peek panics if the heap is empty. The complexity is O(1).

func (*Heap[E]) Pop

func (h *Heap[E]) Pop() E

Pop removes and returns the minimum element (according to the less function) from the heap. Pop panics if the heap is empty. The complexity is O(log n) where n = h.Len().

func (*Heap[E]) Push

func (h *Heap[E]) Push(elem E)

Push pushes an element onto the heap. The complexity is O(log n) where n = h.Len().

Jump to

Keyboard shortcuts

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