lotus/request_queue.go

46 lines
851 B
Go
Raw Normal View History

2020-05-07 23:38:05 +00:00
package sectorstorage
import "sort"
2020-05-07 23:38:05 +00:00
type requestQueue []*workerRequest
func (q requestQueue) Len() int { return len(q) }
func (q requestQueue) Less(i, j int) bool {
2020-06-24 21:06:56 +00:00
if q[i].priority != q[j].priority {
return q[i].priority > q[j].priority
}
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 *workerRequest) {
2020-05-07 23:38:05 +00:00
n := len(*q)
item := x
2020-05-07 23:38:05 +00:00
item.index = n
*q = append(*q, item)
sort.Sort(q)
2020-05-07 23:38:05 +00:00
}
func (q *requestQueue) Remove(i int) *workerRequest {
2020-05-07 23:38:05 +00:00
old := *q
n := len(old)
item := old[i]
2020-07-27 11:21:36 +00:00
old[i] = old[n-1]
old[n-1] = nil
item.index = -1
2020-05-07 23:38:05 +00:00
*q = old[0 : n-1]
sort.Sort(q)
2020-05-07 23:38:05 +00:00
return item
}