Skip to content

Commit 8b76a00

Browse files
committed
Rename all priorityQueue receivers as q, the first alphabet of queue.
1 parent ffe4195 commit 8b76a00

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

policy/lfu/priotiry_queue.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,29 @@ func newPriorityQueue[K comparable, V any](cap int) *priorityQueue[K, V] {
4040
// see example of priority queue: https://pkg.go.dev/container/heap
4141
var _ heap.Interface = (*priorityQueue[struct{}, interface{}])(nil)
4242

43-
func (l priorityQueue[K, V]) Len() int { return len(l) }
43+
func (q priorityQueue[K, V]) Len() int { return len(q) }
4444

45-
func (l priorityQueue[K, V]) Less(i, j int) bool {
46-
if l[i].referenceCount == l[j].referenceCount {
47-
return l[i].referencedAt.Before(l[j].referencedAt)
45+
func (q priorityQueue[K, V]) Less(i, j int) bool {
46+
if q[i].referenceCount == q[j].referenceCount {
47+
return q[i].referencedAt.Before(q[j].referencedAt)
4848
}
49-
return l[i].referenceCount < l[j].referenceCount
49+
return q[i].referenceCount < q[j].referenceCount
5050
}
5151

52-
func (l priorityQueue[K, V]) Swap(i, j int) {
53-
l[i], l[j] = l[j], l[i]
54-
l[i].index = i
55-
l[j].index = j
52+
func (q priorityQueue[K, V]) Swap(i, j int) {
53+
q[i], q[j] = q[j], q[i]
54+
q[i].index = i
55+
q[j].index = j
5656
}
5757

58-
func (l *priorityQueue[K, V]) Push(x interface{}) {
58+
func (q *priorityQueue[K, V]) Push(x interface{}) {
5959
entry := x.(*entry[K, V])
60-
entry.index = len(*l)
61-
*l = append(*l, entry)
60+
entry.index = len(*q)
61+
*q = append(*q, entry)
6262
}
6363

64-
func (l *priorityQueue[K, V]) Pop() interface{} {
65-
old := *l
64+
func (q *priorityQueue[K, V]) Pop() interface{} {
65+
old := *q
6666
n := len(old)
6767
entry := old[n-1]
6868
old[n-1] = nil // avoid memory leak
@@ -71,12 +71,12 @@ func (l *priorityQueue[K, V]) Pop() interface{} {
7171
for i := 0; i < len(new); i++ {
7272
new[i].index = i
7373
}
74-
*l = new
74+
*q = new
7575
return entry
7676
}
7777

78-
func (pq *priorityQueue[K, V]) update(e *entry[K, V], val V) {
78+
func (q *priorityQueue[K, V]) update(e *entry[K, V], val V) {
7979
e.val = val
8080
e.referenced()
81-
heap.Fix(pq, e.index)
81+
heap.Fix(q, e.index)
8282
}

0 commit comments

Comments
 (0)