2021-09-20 08:52:54 +00:00
|
|
|
package torrent
|
|
|
|
|
|
|
|
import (
|
2022-05-09 01:34:08 +00:00
|
|
|
"github.com/anacrolix/torrent/typed-roaring"
|
2021-09-20 08:52:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Return the number of bits set in the range. To do this we need the rank of the item before the
|
|
|
|
// first, and the rank of the last item. An off-by-one minefield. Hopefully I haven't missed
|
|
|
|
// something in roaring's API that provides this.
|
2022-05-09 01:34:08 +00:00
|
|
|
func roaringBitmapRangeCardinality[T typedRoaring.BitConstraint](bm interface{ Rank(T) uint64 }, start, end T) (card uint64) {
|
2021-09-20 08:52:54 +00:00
|
|
|
card = bm.Rank(end - 1)
|
|
|
|
if start != 0 {
|
|
|
|
card -= bm.Rank(start - 1)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|