MCPcopy
hub / github.com/arnauddri/algorithms / ChangePriority

Method ChangePriority

data-structures/priority-queue/priority_queue.go:52–72  ·  view source on GitHub ↗
(val interface{}, priority int)

Source from the content-addressed store, hash-verified

50}
51
52func (pq *PQ) ChangePriority(val interface{}, priority int) {
53 var storage = queue.New()
54
55 popped := pq.Extract()
56
57 for val != popped.Value {
58 if pq.Len() == 0 {
59 panic("Item not found")
60 }
61
62 storage.Push(popped)
63 popped = pq.Extract()
64 }
65
66 popped.Priority = priority
67 pq.data.Insert(popped)
68
69 for storage.Len() > 0 {
70 pq.data.Insert(storage.Shift().(heap.Item))
71 }
72}

Callers 2

TestChangePriorityFunction · 0.80
ShortestPathFunction · 0.80

Calls 5

ExtractMethod · 0.95
LenMethod · 0.95
ShiftMethod · 0.80
PushMethod · 0.45
InsertMethod · 0.45

Tested by 1

TestChangePriorityFunction · 0.64