1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-04 12:52:28 +08:00

feat: add Size func for PriorityQueue

This commit is contained in:
dudaodong
2022-06-05 17:29:36 +08:00
parent 61251fb0f1
commit a706d488e6
3 changed files with 628 additions and 0 deletions

View File

@@ -29,6 +29,11 @@ func (q *PriorityQueue[T]) IsEmpty() bool {
return q.size == 0
}
// Size get number of items in the queue
func (q *PriorityQueue[T]) Size() int {
return q.size
}
// IsFull checks if the queue capacity is full or not
func (q *PriorityQueue[T]) IsFull() bool {
return q.size == len(q.items)-1

View File

@@ -52,9 +52,13 @@ func TestPriorityQueue_Dequeue(t *testing.T) {
pq.Enqueue(i)
}
assert.Equal(10, pq.Size())
val, ok := pq.Dequeue()
assert.Equal(true, ok)
assert.Equal(10, val)
assert.Equal([]int{9, 8, 6, 7, 3, 2, 5, 1, 4}, pq.Data())
assert.Equal(9, pq.Size())
}