| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package main |
| 6 |
|
| 7 |
import ( |
| 8 |
"cmp" |
| 9 |
|
| 10 |
pq "github.com/emirpasic/gods/v2/queues/priorityqueue" |
| 11 |
) |
| 12 |
|
| 13 |
|
| 14 |
type Element struct { |
| 15 |
name string |
| 16 |
priority int |
| 17 |
} |
| 18 |
|
| 19 |
|
| 20 |
func byPriority(a, b Element) int { |
| 21 |
return -cmp.Compare(a.priority, b.priority) |
| 22 |
} |
| 23 |
|
| 24 |
|
| 25 |
func main() { |
| 26 |
a := Element{name: "a", priority: 1} |
| 27 |
b := Element{name: "b", priority: 2} |
| 28 |
c := Element{name: "c", priority: 3} |
| 29 |
|
| 30 |
queue := pq.NewWith(byPriority) |
| 31 |
queue.Enqueue(a) |
| 32 |
queue.Enqueue(c) |
| 33 |
queue.Enqueue(b) |
| 34 |
_ = queue.Values() |
| 35 |
_, _ = queue.Peek() |
| 36 |
_, _ = queue.Dequeue() |
| 37 |
_, _ = queue.Dequeue() |
| 38 |
_, _ = queue.Dequeue() |
| 39 |
_, _ = queue.Dequeue() |
| 40 |
queue.Clear() |
| 41 |
_ = queue.Empty() |
| 42 |
_ = queue.Size() |
| 43 |
} |