2020-05-07 23:38:05 +00:00
|
|
|
package sectorstorage
|
|
|
|
|
|
|
|
import "container/heap"
|
|
|
|
|
|
|
|
type requestQueue []*workerRequest
|
|
|
|
|
|
|
|
func (q requestQueue) Len() int { return len(q) }
|
|
|
|
|
|
|
|
func (q requestQueue) Less(i, j int) bool {
|
2020-05-13 23:56:21 +00:00
|
|
|
if q[i].taskType != q[j].taskType {
|
|
|
|
return q[i].taskType.Less(q[j].taskType)
|
|
|
|
}
|
|
|
|
|
|
|
|
return q[i].sector.Number < q[j].sector.Number // optimize minerActor.NewSectors bitfield
|
2020-05-07 23:38:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q requestQueue) Swap(i, j int) {
|
|
|
|
q[i], q[j] = q[j], q[i]
|
|
|
|
q[i].index = i
|
|
|
|
q[j].index = j
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *requestQueue) Push(x interface{}) {
|
|
|
|
n := len(*q)
|
|
|
|
item := x.(*workerRequest)
|
|
|
|
item.index = n
|
|
|
|
*q = append(*q, item)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *requestQueue) Pop() interface{} {
|
|
|
|
old := *q
|
|
|
|
n := len(old)
|
|
|
|
item := old[n-1]
|
|
|
|
old[n-1] = nil // avoid memory leak
|
|
|
|
item.index = -1 // for safety
|
|
|
|
*q = old[0 : n-1]
|
|
|
|
return item
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ heap.Interface = &requestQueue{}
|