MCPcopy Create free account
hub / github.com/RoaringBitmap/roaring / Rank

Method Rank

roaring64/roaring64.go:397–411  ·  view source on GitHub ↗

Rank returns the number of integers that are smaller or equal to x (Rank(infinity) would be GetCardinality())

(x uint64)

Source from the content-addressed store, hash-verified

395
396// Rank returns the number of integers that are smaller or equal to x (Rank(infinity) would be GetCardinality())
397func (rb *Bitmap) Rank(x uint64) uint64 {
398 size := uint64(0)
399 for i := 0; i < rb.highlowcontainer.size(); i++ {
400 key := rb.highlowcontainer.getKeyAtIndex(i)
401 if key > highbits(x) {
402 return size
403 }
404 if key < highbits(x) {
405 size += rb.highlowcontainer.getContainerAtIndex(i).GetCardinality()
406 } else {
407 return size + rb.highlowcontainer.getContainerAtIndex(i).Rank(lowbits(x))
408 }
409 }
410 return size
411}
412
413// Select returns the xth integer in the bitmap
414func (rb *Bitmap) Select(x uint64) (uint64, error) {

Callers 4

TestBitmapRankCOWFunction · 0.95
TestBitmapRank2Function · 0.95
TestBitmapRankFunction · 0.95
Test64BitValuesFunction · 0.45

Calls 6

highbitsFunction · 0.70
lowbitsFunction · 0.70
sizeMethod · 0.45
getKeyAtIndexMethod · 0.45
GetCardinalityMethod · 0.45
getContainerAtIndexMethod · 0.45

Tested by 4

TestBitmapRankCOWFunction · 0.76
TestBitmapRank2Function · 0.76
TestBitmapRankFunction · 0.76
Test64BitValuesFunction · 0.36