heap

package
v2.7.0-nightly.20230616 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: Apache-2.0 Imports: 0 Imported by: 0

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 any, S ~[]E](h S, lt func(a, b E) bool) (E, S)

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

func Push

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

Push adds x to the heap h

Types

type Heap

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

Heap is a min-heap, implemented using a slice

func New

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

New creates a new Heap and returns it. The heap will use lt for comparisons. lt must return true if a < b and false otherwise. lt should be a pure function of a and b, and should not retain either after it returns.

func (*Heap[T]) Len

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

func (*Heap[T]) Peek

func (h *Heap[T]) Peek() (ret T, exists bool)

func (*Heap[T]) Pop

func (h *Heap[T]) Pop() (ret T, exists bool)

func (*Heap[T]) Push

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

Jump to

Keyboard shortcuts

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