Documentation
¶
Overview ¶
Package priority implements a PriorityQueue
From: https://pkg.go.dev/container/heap@go1.17.6#example-package-PriorityQueue
Index ¶
- type Item
- type Queue
- func (pq Queue) Len() int
- func (pq Queue) Less(i, j int) bool
- func (pq *Queue) Pop() interface{}
- func (pq *Queue) PopValue() string
- func (pq *Queue) Push(x interface{})
- func (pq *Queue) PushValue(value string) *Item
- func (pq Queue) Swap(i, j int)
- func (pq *Queue) Update(item *Item, value string, priority int)
- func (pq *Queue) UpdatePriority(item *Item, priority int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Item ¶
type Item struct { Value string // The Value of the item; arbitrary. Priority int // The Priority of the item in the queue. // The Index is needed by Update and is maintained by the Priority.Interface methods. Index int // The Index of the item in the Priority. }
An Item is something we manage in a Priority queue.
type Queue ¶
type Queue []*Item
A Queue implements Priority.Interface and holds Items.
A Queue with some items, adds and manipulates an item, and then removes the items in Priority order.
Example:
// Some items and their priorities. items := map[string]int{ "banana": 3, "apple": 2, "pear": 4, } // Create a Priority queue, put the items in it, and // establish the Priority queue (Priority) invariants. pq := make(Queue, len(items)) i := 0 for Value, Priority := range items { pq[i] = &Item{ Value: Value, Priority: Priority, Index: i, } i++ } Priority.Init(&pq) // Insert a new item and then modify its Priority. item := &Item{ Value: "orange", Priority: 1, } Priority.Push(&pq, item) pq.Update(item, item.Value, 5) // Take the items out; they arrive in decreasing Priority order. for pq.Len() > 0 { item := Priority.Pop(&pq).(*Item) fmt.Printf("%.2d:%s ", item.Priority, item.Value) }
From: https://pkg.go.dev/container/heap@go1.17.6#example-package-PriorityQueue
func (*Queue) UpdatePriority ¶
Click to show internal directories.
Click to hide internal directories.