lotus/storage/sealer/request_queue.go

51 lines
954 B
Go
Raw Permalink Normal View History

package sealer
2020-05-07 23:38:05 +00:00
import "sort"
2020-05-07 23:38:05 +00:00
type RequestQueue []*WorkerRequest
2020-05-07 23:38:05 +00:00
func (q RequestQueue) Len() int { return len(q) }
2020-05-07 23:38:05 +00:00
func (q RequestQueue) Less(i, j int) bool {
oneMuchLess, muchLess := q[i].TaskType.MuchLess(q[j].TaskType)
if oneMuchLess {
return muchLess
}
if q[i].Priority != q[j].Priority {
return q[i].Priority > q[j].Priority
2020-06-24 21:06:56 +00:00
}
if q[i].TaskType != q[j].TaskType {
return q[i].TaskType.Less(q[j].TaskType)
}
return q[i].Sector.ID.Number < q[j].Sector.ID.Number // optimize minerActor.NewSectors bitfield
2020-05-07 23:38:05 +00:00
}
func (q RequestQueue) Swap(i, j int) {
2020-05-07 23:38:05 +00:00
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
}