heaps

package
v0.0.0-...-cb92b4e Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2023 License: MPL-2.0 Imports: 1 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Peek

func Peek[E any, S ~[]E](h S) E

Peek returns the lowest element of h. h is not modified

func Pop

func Pop[E constraints.Ordered, S ~[]E](h S) (E, S)

func PopFunc

func PopFunc[E any, S ~[]E](h S, lt func(a, b E) bool) (E, S)

PopFunc removes the minimum element from h and returns it and an updated S.

func Push

func Push[E constraints.Ordered, S ~[]E](h S, x E) S

PushFunc adds x to the heap h

func PushFunc

func PushFunc[E any, S ~[]E](h S, x E, lt func(a, b E) bool) S

Types

type Heap

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

Heap is a min heap of Ts

func New

func New[T any](lt func(a, b T) bool) Heap[T]

New creates a new heap

func (*Heap[T]) Len

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

func (*Heap[T]) Peek

func (h *Heap[T]) Peek() (ret T)

Peek returns the minimum element of the heap without removing it.

func (*Heap[T]) Pop

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

Pop removes the minimum element from the heap and returns it.

func (*Heap[T]) Push

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

Push adds an element to the heap

Jump to

Keyboard shortcuts

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