MCPcopy Create free account
hub / github.com/beeker1121/goque / Example_priorityQueue

Function Example_priorityQueue

example_priority_queue_test.go:10–52  ·  view source on GitHub ↗

ExamplePriorityQueue demonstrates the implementation of a Goque queue.

()

Source from the content-addressed store, hash-verified

8
9// ExamplePriorityQueue demonstrates the implementation of a Goque queue.
10func Example_priorityQueue() {
11 // Open/create a priority queue.
12 pq, err := goque.OpenPriorityQueue("data_dir", goque.ASC)
13 if err != nil {
14 fmt.Println(err)
15 return
16 }
17 defer pq.Close()
18
19 // Enqueue the item.
20 item, err := pq.Enqueue(0, []byte("item value"))
21 if err != nil {
22 fmt.Println(err)
23 return
24 }
25
26 fmt.Println(item.ID) // 1
27 fmt.Println(item.Priority) // 0
28 fmt.Println(item.Key) // [0 58 0 0 0 0 0 0 0 1]
29 fmt.Println(item.Value) // [105 116 101 109 32 118 97 108 117 101]
30 fmt.Println(item.ToString()) // item value
31
32 // Change the item value in the queue.
33 item, err = pq.Update(item.Priority, item.ID, []byte("new item value"))
34 if err != nil {
35 fmt.Println(err)
36 return
37 }
38
39 fmt.Println(item.ToString()) // new item value
40
41 // Dequeue the next item.
42 deqItem, err := pq.Dequeue()
43 if err != nil {
44 fmt.Println(err)
45 return
46 }
47
48 fmt.Println(deqItem.ToString()) // new item value
49
50 // Delete the queue and its database.
51 pq.Drop()
52}

Callers

nothing calls this directly

Calls 7

OpenPriorityQueueFunction · 0.92
CloseMethod · 0.45
EnqueueMethod · 0.45
ToStringMethod · 0.45
UpdateMethod · 0.45
DequeueMethod · 0.45
DropMethod · 0.45

Tested by

no test coverage detected