2020-05-07 23:38:05 +00:00
|
|
|
package sectorstorage
|
|
|
|
|
2020-07-27 11:20:18 +00:00
|
|
|
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-08-27 21:28:52 +00:00
|
|
|
oneMuchLess, muchLess := q[i].taskType.MuchLess(q[j].taskType)
|
|
|
|
if oneMuchLess {
|
|
|
|
return muchLess
|
|
|
|
}
|
|
|
|
|
2020-06-24 21:06:56 +00:00
|
|
|
if q[i].priority != q[j].priority {
|
|
|
|
return q[i].priority > q[j].priority
|
|
|
|
}
|
|
|
|
|
2020-05-13 23:56:21 +00:00
|
|
|
if q[i].taskType != q[j].taskType {
|
|
|
|
return q[i].taskType.Less(q[j].taskType)
|
|
|
|
}
|
|
|
|
|
2020-11-04 20:29:08 +00:00
|
|
|
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) {
|
|
|
|
q[i], q[j] = q[j], q[i]
|
|
|
|
q[i].index = i
|
|
|
|
q[j].index = j
|
|
|
|
}
|
|
|
|
|
2020-07-27 11:20:18 +00:00
|
|
|
func (q *requestQueue) Push(x *workerRequest) {
|
2020-05-07 23:38:05 +00:00
|
|
|
n := len(*q)
|
2020-07-27 11:20:18 +00:00
|
|
|
item := x
|
2020-05-07 23:38:05 +00:00
|
|
|
item.index = n
|
|
|
|
*q = append(*q, item)
|
2020-07-27 11:20:18 +00:00
|
|
|
sort.Sort(q)
|
2020-05-07 23:38:05 +00:00
|
|
|
}
|
|
|
|
|
2020-07-27 11:20:18 +00:00
|
|
|
func (q *requestQueue) Remove(i int) *workerRequest {
|
2020-05-07 23:38:05 +00:00
|
|
|
old := *q
|
|
|
|
n := len(old)
|
2020-07-27 11:20:18 +00:00
|
|
|
item := old[i]
|
2020-07-27 11:21:36 +00:00
|
|
|
old[i] = old[n-1]
|
|
|
|
old[n-1] = nil
|
2020-07-27 11:20:18 +00:00
|
|
|
item.index = -1
|
2020-05-07 23:38:05 +00:00
|
|
|
*q = old[0 : n-1]
|
2020-07-27 11:20:18 +00:00
|
|
|
sort.Sort(q)
|
2020-05-07 23:38:05 +00:00
|
|
|
return item
|
|
|
|
}
|