queue

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 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 PriorityQueue

type PriorityQueue struct {
	Order bool                 // Order specifies whether the priority queue is in ascending or descending order.
	Items []*PriorityQueueItem // Items contains the elements of the priority queue.
}

PriorityQueue implements heap.Interface and holds PriorityQueueItems.

func NewMax added in v0.0.10

func NewMax(capacity int) *PriorityQueue

NewMax initializes a new priority queue with maximum priority.

func NewMin added in v0.0.10

func NewMin(capacity int) *PriorityQueue

NewMin initializes a new priority queue with minimum priority.

func (*PriorityQueue) Len

func (pq *PriorityQueue) Len() int

Len returns the number of elements in the priority queue.

func (*PriorityQueue) Less

func (pq *PriorityQueue) Less(i, j int) bool

Less reports whether the element with index i should sort before the element with index j.

func (*PriorityQueue) Pop

func (pq *PriorityQueue) Pop() any

Pop removes and returns the top element from the priority queue.

func (*PriorityQueue) Push

func (pq *PriorityQueue) Push(x any)

Push adds x to the priority queue.

func (*PriorityQueue) Swap

func (pq *PriorityQueue) Swap(i, j int)

Swap swaps the elements with indexes i and j.

func (*PriorityQueue) Top

func (pq *PriorityQueue) Top() any

Top returns the top element of the priority queue.

type PriorityQueueItem

type PriorityQueueItem struct {
	Node     uint32  // Node is the value of the item, which can be arbitrary.
	Distance float32 // Distance is the priority of the item in the queue.
	Index    int     // Index is needed by update and is maintained by the heap.Interface methods.
}

PriorityQueueItem represents an item in the priority queue.

Jump to

Keyboard shortcuts

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