@@ -22,7 +22,7 @@ import (
22
22
"container/heap"
23
23
)
24
24
25
- // Priority queue data structure.
25
+ // Prque is a priority queue data structure.
26
26
type Prque [P cmp.Ordered , V any ] struct {
27
27
cont * sstack [P , V ]
28
28
}
@@ -32,7 +32,7 @@ func New[P cmp.Ordered, V any](setIndex SetIndexCallback[V]) *Prque[P, V] {
32
32
return & Prque [P , V ]{newSstack [P , V ](setIndex )}
33
33
}
34
34
35
- // Pushes a value with a given priority into the queue, expanding if necessary.
35
+ // Push a value with a given priority into the queue, expanding if necessary.
36
36
func (p * Prque [P , V ]) Push (data V , priority P ) {
37
37
heap .Push (p .cont , & item [P , V ]{data , priority })
38
38
}
@@ -43,14 +43,14 @@ func (p *Prque[P, V]) Peek() (V, P) {
43
43
return item .value , item .priority
44
44
}
45
45
46
- // Pops the value with the greatest priority off the stack and returns it.
46
+ // Pop the value with the greatest priority off the stack and returns it.
47
47
// Currently no shrinking is done.
48
48
func (p * Prque [P , V ]) Pop () (V , P ) {
49
49
item := heap .Pop (p .cont ).(* item [P , V ])
50
50
return item .value , item .priority
51
51
}
52
52
53
- // Pops only the item from the queue, dropping the associated priority value.
53
+ // PopItem pops only the item from the queue, dropping the associated priority value.
54
54
func (p * Prque [P , V ]) PopItem () V {
55
55
return heap .Pop (p .cont ).(* item [P , V ]).value
56
56
}
@@ -60,17 +60,17 @@ func (p *Prque[P, V]) Remove(i int) V {
60
60
return heap .Remove (p .cont , i ).(* item [P , V ]).value
61
61
}
62
62
63
- // Checks whether the priority queue is empty.
63
+ // Empty checks whether the priority queue is empty.
64
64
func (p * Prque [P , V ]) Empty () bool {
65
65
return p .cont .Len () == 0
66
66
}
67
67
68
- // Returns the number of element in the priority queue.
68
+ // Size returns the number of element in the priority queue.
69
69
func (p * Prque [P , V ]) Size () int {
70
70
return p .cont .Len ()
71
71
}
72
72
73
- // Clears the contents of the priority queue.
73
+ // Reset clears the contents of the priority queue.
74
74
func (p * Prque [P , V ]) Reset () {
75
75
* p = * New [P , V ](p .cont .setIndex )
76
76
}
0 commit comments