1 package requestStrategy
3 import "github.com/anacrolix/torrent/metainfo"
6 Delete(pieceRequestOrderItem)
7 Add(pieceRequestOrderItem)
8 Scan(func(pieceRequestOrderItem) bool)
11 func NewPieceOrder(btree Btree, cap int) *PieceRequestOrder {
12 return &PieceRequestOrder{
14 keys: make(map[PieceRequestOrderKey]PieceRequestOrderState, cap),
18 type PieceRequestOrder struct {
20 keys map[PieceRequestOrderKey]PieceRequestOrderState
23 type PieceRequestOrderKey struct {
24 InfoHash metainfo.Hash
28 type PieceRequestOrderState struct {
29 Priority piecePriority
34 type pieceRequestOrderItem struct {
35 key PieceRequestOrderKey
36 state PieceRequestOrderState
39 func (me *pieceRequestOrderItem) Less(otherConcrete *pieceRequestOrderItem) bool {
40 return pieceOrderLess(me, otherConcrete).Less()
43 func (me *PieceRequestOrder) Add(key PieceRequestOrderKey, state PieceRequestOrderState) {
44 if _, ok := me.keys[key]; ok {
47 me.tree.Add(pieceRequestOrderItem{key, state})
51 func (me *PieceRequestOrder) Update(
52 key PieceRequestOrderKey,
53 state PieceRequestOrderState,
55 oldState, ok := me.keys[key]
57 panic("key should have been added already")
59 if state == oldState {
62 me.tree.Delete(pieceRequestOrderItem{key, oldState})
63 me.tree.Add(pieceRequestOrderItem{key, state})
67 func (me *PieceRequestOrder) existingItemForKey(key PieceRequestOrderKey) pieceRequestOrderItem {
68 return pieceRequestOrderItem{
74 func (me *PieceRequestOrder) Delete(key PieceRequestOrderKey) {
75 me.tree.Delete(pieceRequestOrderItem{key, me.keys[key]})
79 func (me *PieceRequestOrder) Len() int {