Atlas › Test
TestNewPriorityQueueWithItems
Exact test identity: go.temporal.io/server/common/collection/TestPriorityQueueSuite/TestNewPriorityQueueWithItems
- Package
go.temporal.io/server/common/collection
- Suite / test hierarchy
TestPriorityQueueSuite/TestNewPriorityQueueWithItems
- Test
TestNewPriorityQueueWithItems
- Introduced at
- priority_queue.go ×1 Frontier kind: Joint frontier
- Covered ranges
- 8
- Covered lines
- 33
- Covered files
- 1
Covered source
Expand a file to inspect source; the > gutter marks covered lines.
go.temporal.io/server/common/collection/priority_queue.go 33 covered LOC · 8 ranges
Open complete file
15
func NewPriorityQueue[T any](
16
compareLess func(this T, other T) bool,
18
>
return &priorityQueueImpl[T]{
19
>
compareLess: compareLess,
20
>
}
21
>
}
22
23
// NewPriorityQueueWithItems creats a new priority queue
29
compareLess func(this T, other T) bool,
30
items []T,
32
>
pq := &priorityQueueImpl[T]{
33
>
compareLess: compareLess,
34
>
items: items,
35
>
}
36
>
heap.Init(pq)
37
>
return pq
38
>
}
39
40
// Peek returns the top item of the priority queue
52
53
// Remove pop an item from priority queue
55
>
return heap.Pop(pq).(T)
56
>
}
57
58
// IsEmpty indicate if the priority queue is empty
60
>
return pq.Len() == 0
61
>
}
62
63
// below are the functions used by heap.Interface and go internal heap implementation
64
65
// Len implements sort.Interface
67
>
return len(pq.items)
68
>
}
69
70
// Less implements sort.Interface
72
>
return pq.compareLess(pq.items[i], pq.items[j])
73
>
}
74
75
// Swap implements sort.Interface
77
>
pq.items[i], pq.items[j] = pq.items[j], pq.items[i]
78
>
}
79
80
// Push push an item to priority queue, used by go internal heap implementation
84
85
// Pop pop an item from priority queue, used by go internal heap implementation
87
>
pqItem := pq.items[pq.Len()-1]
88
>
pq.items = pq.items[0 : pq.Len()-1]
89
>
return pqItem
90
>
}