heaps

package
v0.0.0-...-5d524ee Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Item

type Item[A any] interface {
	comparable

	// Less returns true if this item is less than the given item.
	Less(A) bool
}

type MinHeap

type MinHeap[A Item[A]] struct {
	// contains filtered or unexported fields
}

MinHeap is a min heap of items.

func NewMinHeap

func NewMinHeap[A Item[A]](capacity ...int) *MinHeap[A]

NewMinHeap returns a new min heap.

func (*MinHeap[A]) Contains

func (h *MinHeap[A]) Contains(item A) bool

Contains returns true if the heap contains the given item.

func (*MinHeap[A]) Insert

func (h *MinHeap[A]) Insert(item A)

Insert inserts the given item into the heap.

func (*MinHeap[A]) Len

func (h *MinHeap[A]) Len() int

func (*MinHeap[A]) Remove

func (h *MinHeap[A]) Remove() A

Remove removes the smallest item from the heap and returns it.

func (*MinHeap[A]) RemoveItem

func (h *MinHeap[A]) RemoveItem(item A)

func (*MinHeap[A]) Update

func (h *MinHeap[A]) Update(item A)

Update updates the given item in the heap.

Jump to

Keyboard shortcuts

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