minheap

package
v1.14.4 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2022 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MinHeap

type MinHeap []*PQItem

Priority queue is based on a regular array

func (MinHeap) Len

func (h MinHeap) Len() int

Len returns the length of a priority queue

func (MinHeap) Less

func (h MinHeap) Less(i, j int) bool

Less defines the order between two priority queue entries

func (*MinHeap) Peek

func (h *MinHeap) Peek() interface{}

Peek returns the top element (min priority)

func (*MinHeap) Pop

func (h *MinHeap) Pop() interface{}

Pop pulls the top (max priority) element from a priority queue. Complexity: O(1)

func (*MinHeap) Push

func (h *MinHeap) Push(x interface{})

Push inserts an element to a priority queue. Complexity: O(logN)

func (MinHeap) Swap

func (h MinHeap) Swap(i, j int)

Swap is used for swapping two priority queue elements on sorting

func (*MinHeap) Update

func (h *MinHeap) Update(item *PQItem, value interface{}, priority int64)

Update allows to change a priority queue item's value and priority. Complexity: O(logN)

type PQItem

type PQItem struct {
	Value    interface{}
	Priority int64
	Index    int
}

PQItem defines a node for a priority queue

Jump to

Keyboard shortcuts

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