queue

package
v0.0.0-...-d8ed7c5 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2023 License: MIT Imports: 2 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 struct {
	ItemId      int // node id of this item
	Priority    int // distance from origin to this node
	Predecessor int // node id of the predecessor
	Index       int // index of the item in the heap
}

func NewQueueItem

func NewQueueItem(itemId int, priority int, predecessor int) *Item

type MinHeap

type MinHeap[T Priorizable] struct {
	Queue   PriorityQueue // hold the priority queue
	Storage []T           // may or may not contain the items in the priority queue. Indexable directly by the ID
}

func NewMinHeap

func NewMinHeap[T Priorizable](items []T) *MinHeap[T]

func (*MinHeap[T]) Len

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

func (*MinHeap[T]) Peek

func (h *MinHeap[T]) Peek() T

func (*MinHeap[T]) PeekAt

func (h *MinHeap[T]) PeekAt(index int) T

func (*MinHeap[T]) Pop

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

func (*MinHeap[T]) Push

func (h *MinHeap[T]) Push(item T)

func (*MinHeap[T]) Remove

func (h *MinHeap[T]) Remove(index int)

func (*MinHeap[T]) String

func (h *MinHeap[T]) String() string

func (*MinHeap[T]) Update

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

type PriorityQueue

type PriorityQueue []Priorizable

Implements heap.Interface

func (PriorityQueue) Len

func (q PriorityQueue) Len() int

func (PriorityQueue) Less

func (q PriorityQueue) Less(i, j int) bool

func (*PriorityQueue) Pop

func (q *PriorityQueue) Pop() any

func (*PriorityQueue) Push

func (q *PriorityQueue) Push(item any)

func (PriorityQueue) Swap

func (q PriorityQueue) Swap(i, j int)

type Priorizable

type Priorizable interface {
	Priority() int
	Index() int
	SetIndex(index int)
	String() string
}

type Queue

type Queue []*Item

A Queue implements the heap.Interface and hold PriorityQueueItems

func NewQueue

func NewQueue(initialItem *Item) *Queue

func (Queue) Len

func (h Queue) Len() int

func (Queue) Less

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

func (*Queue) Pop

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

func (*Queue) Push

func (h *Queue) Push(item interface{})

func (Queue) Swap

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

func (*Queue) Update

func (h *Queue) Update(pqItem *Item, newPriority int)

Jump to

Keyboard shortcuts

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