sliceheap

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package slicehap provides a minimal generic heap implementation backed by a slice and compatible with container/heap.

It intentionally continas no additional policy. Ordering is fully defined by the provided Less function.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Heap

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

Heap is a slice backed implementation of container/heap.Interface

func New

func New[T any](cap int, less Less[T], vals ...T) *Heap[T]

New constructs a new Heap with the given capacity, ordering function, and optional initial values.

The heap invariant is established during construction.

func (*Heap[T]) Len

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

Less implements container/heap.Interface.

func (*Heap[T]) Less

func (h *Heap[T]) Less(i, j int) bool

Less implements container/heap.Interface.

func (*Heap[T]) Pop

func (h *Heap[T]) Pop() any

Pop implements container/heap.Interface.

func (*Heap[T]) Push

func (h *Heap[T]) Push(x any)

Push implements container/heap.Interface.

func (*Heap[T]) Slice

func (h *Heap[T]) Slice() []T

Slice exposes the underlying slice for inspection. The caller must not mutate it in ways that violate the heap invariant.

Note that the ordering of elements in the slice may be non-intuitive, as only the heap invariant is guaranteed.

func (*Heap[T]) Swap

func (h *Heap[T]) Swap(i, j int)

Swap implements container/heap.Interface.

type Less

type Less[T any] func(a, b T) bool

Less defines the ordering relation for heap elements.

Jump to

Keyboard shortcuts

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