https://github.com/skillcoder/pqueue
Priority queue built using the heap interface
https://github.com/skillcoder/pqueue
Last synced: 4 months ago
JSON representation
Priority queue built using the heap interface
- Host: GitHub
- URL: https://github.com/skillcoder/pqueue
- Owner: skillcoder
- License: apache-2.0
- Created: 2021-07-25T20:09:38.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-04-17T16:03:30.000Z (about 3 years ago)
- Last Synced: 2025-01-13T23:33:01.403Z (5 months ago)
- Language: Go
- Size: 6.84 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pqueue
Priority queue built using the heap interface
## USING
```go
// Some items and their priorities.
items := map[int]int{
1: 10, 2: 20, 3: 5,
}// Create a priority queue, put the items in it, and
// establish the priority queue (heap) invariants.
pq := make(Priority, len(items))
i := 0
pq.Push(&Item{value: 0, priority: 0})
for value, priority := range items {
pq[i] = &Item{
value: value,
priority: priority,
index: i,
}
i++
}
heap.Init(&pq)// Take the items out; they arrive in decreasing priority order.
fmt.Println(heap.Pop(&pq).(*Item))
fmt.Println(heap.Pop(&pq).(*Item))
fmt.Println(heap.Pop(&pq).(*Item))
fmt.Println(heap.Pop(&pq).(*Item))
```