]> Sergey Matveev's repositories - btrtrc.git/blob - roaring.go
Drop support for go 1.20
[btrtrc.git] / roaring.go
1 package torrent
2
3 import (
4         "github.com/anacrolix/torrent/typed-roaring"
5 )
6
7 // Return the number of bits set in the range. To do this we need the rank of the item before the
8 // first, and the rank of the last item. An off-by-one minefield. Hopefully I haven't missed
9 // something in roaring's API that provides this.
10 func roaringBitmapRangeCardinality[T typedRoaring.BitConstraint](bm interface{ Rank(T) uint64 }, start, end T) (card uint64) {
11         card = bm.Rank(end - 1)
12         if start != 0 {
13                 card -= bm.Rank(start - 1)
14         }
15         return
16 }