https://github.com/beevik/pq
generic priority queue in go
https://github.com/beevik/pq
Last synced: 10 months ago
JSON representation
generic priority queue in go
- Host: GitHub
- URL: https://github.com/beevik/pq
- Owner: beevik
- License: bsd-2-clause
- Created: 2025-03-09T07:56:04.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-09T07:57:47.000Z (about 1 year ago)
- Last Synced: 2025-03-09T08:26:24.930Z (about 1 year ago)
- Language: Go
- Size: 0 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
pq
==
A generic implementation of a priority queue in Go. The queue is implemented
as a min-heap, with the key value used as a priority value. Items with
smallest key value are dequeued first.
```go
q := pq.NewQueue[int, string]()
q.Enqueue(3, "three")
q.Enqueue(1, "one")
q.Enqueue(5, "five")
fmt.Printf("Queue size: %d\n", q.Count())
k, v := q.Peek()
fmt.Printf("Peek: %d %s\n", k, v)
for !q.IsEmpty() {
k, v = q.Dequeue()
fmt.Printf("Dequeue: %d %s\n", k, v)
}
```
Output:
```
Queue size: 3
Peek: 1 one
Dequeue: 1 one
Dequeue: 3 three
Dequeue: 5 five
```