forked from adrianbrad/queue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_priority_test.go
60 lines (46 loc) · 1.06 KB
/
example_priority_test.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_test
import (
"fmt"
"github.com/adrianbrad/queue"
)
func ExamplePriority() {
elems := []int{2, 4, 1}
priorityQueue := queue.NewPriority(
elems,
func(elem, otherElem int) bool {
return elem < otherElem
},
queue.WithCapacity(4),
)
containsTwo := priorityQueue.Contains(2)
fmt.Println("Contains 2:", containsTwo)
size := priorityQueue.Size()
fmt.Println("Size:", size)
if err := priorityQueue.Offer(3); err != nil {
fmt.Println("Offer err: ", err)
return
}
empty := priorityQueue.IsEmpty()
fmt.Println("Empty before clear:", empty)
clearElems := priorityQueue.Clear()
fmt.Println("Clear:", clearElems)
empty = priorityQueue.IsEmpty()
fmt.Println("Empty after clear:", empty)
if err := priorityQueue.Offer(5); err != nil {
fmt.Println("Offer err: ", err)
return
}
elem, err := priorityQueue.Get()
if err != nil {
fmt.Println("Get err: ", err)
return
}
fmt.Println("Get:", elem)
// Output:
// Contains 2: true
// Size: 3
// Empty before clear: false
// Clear: [1 2 3 4]
// Empty after clear: true
// Get: 5
}