2021-12-18 13:07:44 +08:00
|
|
|
package request_strategy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/tidwall/btree"
|
|
|
|
)
|
|
|
|
|
|
|
|
type tidwallBtree struct {
|
2022-12-31 10:25:00 +08:00
|
|
|
tree *btree.BTreeG[pieceRequestOrderItem]
|
2021-12-18 13:07:44 +08:00
|
|
|
PathHint *btree.PathHint
|
|
|
|
}
|
|
|
|
|
|
|
|
func (me *tidwallBtree) Scan(f func(pieceRequestOrderItem) bool) {
|
|
|
|
me.tree.Scan(f)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewTidwallBtree() *tidwallBtree {
|
|
|
|
return &tidwallBtree{
|
2022-12-31 10:25:00 +08:00
|
|
|
tree: btree.NewBTreeGOptions(
|
2021-12-18 13:07:44 +08:00
|
|
|
func(a, b pieceRequestOrderItem) bool {
|
|
|
|
return a.Less(&b)
|
|
|
|
},
|
2022-12-31 10:25:00 +08:00
|
|
|
btree.Options{NoLocks: true, Degree: 64}),
|
2021-12-18 13:07:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (me *tidwallBtree) Add(item pieceRequestOrderItem) {
|
|
|
|
if _, ok := me.tree.SetHint(item, me.PathHint); ok {
|
|
|
|
panic("shouldn't already have this")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type PieceRequestOrderPathHint = btree.PathHint
|
|
|
|
|
|
|
|
func (me *tidwallBtree) Delete(item pieceRequestOrderItem) {
|
|
|
|
_, deleted := me.tree.DeleteHint(item, me.PathHint)
|
|
|
|
mustValue(deleted, item)
|
|
|
|
}
|