-
Notifications
You must be signed in to change notification settings - Fork 0
/
priority.go
60 lines (47 loc) · 1.07 KB
/
priority.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package queue
import (
"github.com/zytekaron/structs"
"github.com/zytekaron/structs/heap"
)
type PriorityQueue[V any] struct {
heap *heap.Heap[V]
}
func NewPriority[V any](cmp structs.CompareFunc[V]) *PriorityQueue[V] {
return &PriorityQueue[V]{
heap: heap.New(cmp),
}
}
func NewPriorityCap[V any](capacity int, cmp structs.CompareFunc[V]) *PriorityQueue[V] {
return &PriorityQueue[V]{
heap: heap.NewCap(capacity, cmp),
}
}
func FromPriorityHeap[V any](h *heap.Heap[V]) *PriorityQueue[V] {
return &PriorityQueue[V]{
heap: h,
}
}
func (p *PriorityQueue[V]) IsEmpty() bool {
return p.heap.IsEmpty()
}
func (p *PriorityQueue[V]) Enqueue(value V) {
p.heap.Push(value)
}
func (p *PriorityQueue[V]) Peek() V {
return p.heap.Peek()
}
func (p *PriorityQueue[V]) Dequeue() V {
return p.heap.Pop()
}
func (p *PriorityQueue[V]) Contains(value V) bool {
return p.heap.Contains(value)
}
func (p *PriorityQueue[V]) Size() int {
return p.heap.Size()
}
func (p *PriorityQueue[V]) Clear() {
p.heap.Clear()
}
func (p *PriorityQueue[V]) Values() []V {
return p.heap.Values()
}