roaring.go 527 B

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