diff options
Diffstat (limited to '')
-rw-r--r-- | dependencies/pkg/mod/github.com/vbauerster/mpb/v6@v6.0.4/priority_queue.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/dependencies/pkg/mod/github.com/vbauerster/mpb/v6@v6.0.4/priority_queue.go b/dependencies/pkg/mod/github.com/vbauerster/mpb/v6@v6.0.4/priority_queue.go new file mode 100644 index 0000000..29d9bd5 --- /dev/null +++ b/dependencies/pkg/mod/github.com/vbauerster/mpb/v6@v6.0.4/priority_queue.go @@ -0,0 +1,32 @@ +package mpb + +// A priorityQueue implements heap.Interface +type priorityQueue []*Bar + +func (pq priorityQueue) Len() int { return len(pq) } + +func (pq priorityQueue) Less(i, j int) bool { + return pq[i].priority < pq[j].priority +} + +func (pq priorityQueue) Swap(i, j int) { + pq[i], pq[j] = pq[j], pq[i] + pq[i].index = i + pq[j].index = j +} + +func (pq *priorityQueue) Push(x interface{}) { + s := *pq + bar := x.(*Bar) + bar.index = len(s) + s = append(s, bar) + *pq = s +} + +func (pq *priorityQueue) Pop() interface{} { + s := *pq + *pq = s[0 : len(s)-1] + bar := s[len(s)-1] + bar.index = -1 // for safety + return bar +} |