MCPcopy
hub / github.com/RoaringBitmap/roaring / Rank

Method Rank

roaring.go:1259–1273  ·  view source on GitHub ↗

Rank returns the number of integers that are smaller or equal to x (Rank(infinity) would be GetCardinality()). If you pass the smallest value, you get the value 1. If you pass a value that is smaller than the smallest value, you get 0. Note that this function differs in convention from the Select fu

(x uint32)

Source from the content-addressed store, hash-verified

1257// value, you get 0. Note that this function differs in convention from the Select function since it
1258// return 1 and not 0 on the smallest value.
1259func (rb *Bitmap) Rank(x uint32) uint64 {
1260 size := uint64(0)
1261 for i := 0; i < rb.highlowcontainer.size(); i++ {
1262 key := rb.highlowcontainer.getKeyAtIndex(i)
1263 if key > highbits(x) {
1264 return size
1265 }
1266 if key < highbits(x) {
1267 size += uint64(rb.highlowcontainer.getContainerAtIndex(i).getCardinality())
1268 } else {
1269 return size + uint64(rb.highlowcontainer.getContainerAtIndex(i).rank(lowbits(x)))
1270 }
1271 }
1272 return size
1273}
1274
1275// CardinalityInRange returns the number of integers that are in the half-open range [start, end).
1276// It is equivalent to Rank(uint32(end-1)) - Rank(uint32(start-1)) for start > 0,

Callers 5

TestBitmapRankCOWFunction · 0.95
TestBitmapRank2Function · 0.95
TestBitmapRankFunction · 0.95

Calls 7

highbitsFunction · 0.70
lowbitsFunction · 0.70
getCardinalityMethod · 0.65
rankMethod · 0.65
sizeMethod · 0.45
getKeyAtIndexMethod · 0.45
getContainerAtIndexMethod · 0.45

Tested by 5

TestBitmapRankCOWFunction · 0.76
TestBitmapRank2Function · 0.76
TestBitmapRankFunction · 0.76