heap

package module
v0.0.0-...-d06da75 Latest Latest
Warning

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

Go to latest
Published: May 19, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init[E any](h Heap[E])

Init establishes the heap invariants required by the other routines in this package. Init is idempotent with respect to the heap invariants and may be called whenever the heap invariants may have been invalidated. The complexity is O(n) where n = h.Len().

Types

type Heap

type Heap[E any] interface {
	Len() int
	Push(E)
	Pop() E
	Peek() E
	Remove(int) E
	Fix(int)
	Queue() iter.Seq[E]
	// contains filtered or unexported methods
}

Heap is a min-heap of elements of type E.

func Concurrent

func Concurrent[E any](heap Heap[E]) Heap[E]

Concurrent returns a concurrent-safe heap based on the given heap. If the given heap is already concurrent-safe, it returns the given heap unchanged.

func New

func New[E any](e []E, less func(E, E) bool) Heap[E]

New creates a new heap from the given elements and less function. The complexity is O(n) where n = len(e). The returned heap is not safe for concurrent use.

Jump to

Keyboard shortcuts

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