]> Sergey Matveev's repositories - btrtrc.git/blob - torrent_pending_pieces.go
Optimize PeerConn.peerHasAllPieces
[btrtrc.git] / torrent_pending_pieces.go
1 package torrent
2
3 import (
4         "github.com/elliotchance/orderedmap"
5
6         "github.com/anacrolix/missinggo/v2/prioritybitmap"
7 )
8
9 type stableSet struct {
10         om *orderedmap.OrderedMap
11 }
12
13 func (s stableSet) Has(bit int) bool {
14         _, ok := s.om.Get(bit)
15         return ok
16 }
17
18 func (s stableSet) Delete(bit int) {
19         s.om.Delete(bit)
20 }
21
22 func (s stableSet) Len() int {
23         return s.om.Len()
24 }
25
26 func (s stableSet) Set(bit int) {
27         s.om.Set(bit, struct{}{})
28 }
29
30 func (s stableSet) Range(f func(int) bool) {
31         for e := s.om.Front(); e != nil; e = e.Next() {
32                 if !f(e.Key.(int)) {
33                         break
34                 }
35         }
36 }
37
38 func priorityBitmapStableNewSet() prioritybitmap.Set {
39         return stableSet{om: orderedmap.NewOrderedMap()}
40 }