skopeo/vendor/github.com/vbauerster/mpb/v8/priority_queue.go
renovate[bot] f17b4c9672
Update module github.com/containers/image/v5 to v5.36.0
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-07-15 21:58:37 +00:00

38 lines
699 B
Go

package mpb
import "container/heap"
var _ heap.Interface = (*priorityQueue)(nil)
type priorityQueue []*Bar
func (pq priorityQueue) Len() int { return len(pq) }
func (pq priorityQueue) Less(i, j int) bool {
// greater priority pops first
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
b := x.(*Bar)
b.index = len(s)
*pq = append(s, b)
}
func (pq *priorityQueue) Pop() interface{} {
var b *Bar
s := *pq
i := len(s) - 1
b, s[i] = s[i], nil // nil to avoid memory leak
b.index = -1 // for safety
*pq = s[:i]
return b
}