heaps

package
v0.2.12 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: MIT Imports: 2 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HeapItem

type HeapItem[T constraints.Ordered] struct {
	Ref   T
	Value any
	// contains filtered or unexported fields
}

type MaxHeap added in v0.2.3

type MaxHeap[T constraints.Ordered] []T

MaxHeap is a min-heap of ints.

func (MaxHeap[T]) Index added in v0.2.3

func (h MaxHeap[T]) Index(e T) int

func (MaxHeap[T]) Len added in v0.2.3

func (h MaxHeap[T]) Len() int

func (MaxHeap[T]) Less added in v0.2.3

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

func (*MaxHeap[T]) Pop added in v0.2.3

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

Pop from heap

func (*MaxHeap[T]) Push added in v0.2.3

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

Push to heap

func (MaxHeap[T]) Swap added in v0.2.3

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

type MaxHeapWithValue

type MaxHeapWithValue[T constraints.Ordered] []*HeapItem[T]

An MaxHeapWithValue is a max-heap of ints.

func (MaxHeapWithValue[T]) Len

func (h MaxHeapWithValue[T]) Len() int

func (MaxHeapWithValue[T]) Less

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

func (*MaxHeapWithValue[T]) Pop

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

Pop from heap

func (*MaxHeapWithValue[T]) Push

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

Push to heap

func (MaxHeapWithValue[T]) Swap

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

type MinHeap

type MinHeap[T constraints.Ordered] []T

MinHeap is a min-heap of ints.

func (MinHeap[T]) Len

func (h MinHeap[T]) Len() int

func (MinHeap[T]) Less

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

func (*MinHeap[T]) Pop

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

Pop from heap

func (*MinHeap[T]) Push

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

Push to heap

func (MinHeap[T]) Swap

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

type MinHeapInt added in v0.2.12

type MinHeapInt[T ToInt] []T

func (MinHeapInt[T]) Len added in v0.2.12

func (h MinHeapInt[T]) Len() int

func (MinHeapInt[T]) Less added in v0.2.12

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

func (*MinHeapInt[T]) Pop added in v0.2.12

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

Pop from heap

func (*MinHeapInt[T]) Push added in v0.2.12

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

Push to heap

func (MinHeapInt[T]) Swap added in v0.2.12

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

type MinHeapWithValue

type MinHeapWithValue[T constraints.Ordered] []*HeapItem[T]

An MinHeapWithValue is a min-heap of ints.

func (MinHeapWithValue[T]) Len

func (h MinHeapWithValue[T]) Len() int

func (MinHeapWithValue[T]) Less

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

func (*MinHeapWithValue[T]) Pop

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

Pop from heap

func (*MinHeapWithValue[T]) Push

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

Push to heap

func (MinHeapWithValue[T]) Swap

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

type PrioritItem

type PrioritItem[T any] struct {
	Value    T   // The value of the item; arbitrary.
	Priority int // The priority of the item in the queue.
	// contains filtered or unexported fields
}

An PrioritItem is something we manage in a priority queue.

type PriorityQueue

type PriorityQueue[T any] []*PrioritItem[T]

A PriorityQueue implements heap.Interface and holds Items.

func (PriorityQueue[T]) Len

func (pq PriorityQueue[T]) Len() int

func (PriorityQueue[T]) Less

func (pq PriorityQueue[T]) Less(i, j int) bool

func (*PriorityQueue[T]) Pop

func (pq *PriorityQueue[T]) Pop() any

Pop an item from the priority queue

func (*PriorityQueue[T]) Push

func (pq *PriorityQueue[T]) Push(x any)

Push a new item into the priority queue

func (PriorityQueue[T]) Swap

func (pq PriorityQueue[T]) Swap(i, j int)

func (*PriorityQueue[T]) Update

func (pq *PriorityQueue[T]) Update(item *PrioritItem[T], value T, priority int)

Update modifies the priority and value of an PrioritItem in the queue.

type ToInt added in v0.2.12

type ToInt interface {
	Int() int
}

type UniqMinHeap

type UniqMinHeap[T constraints.Ordered] struct {
	// contains filtered or unexported fields
}

An UniqMinHeap is a min-heap of ints.

func NewUniqMinHeap

func NewUniqMinHeap[T constraints.Ordered]() UniqMinHeap[T]

func (UniqMinHeap[T]) Len

func (h UniqMinHeap[T]) Len() int

func (UniqMinHeap[T]) Less

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

func (*UniqMinHeap[T]) Pop

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

Pop from heap

func (*UniqMinHeap[T]) Push

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

Push to heap

func (UniqMinHeap[T]) Swap

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

Jump to

Keyboard shortcuts

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