lotus/request_queue.go

41 lines
815 B
Go
Raw Normal View History

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 {
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{}