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

Method Select

roaring.go:1351–1364  ·  view source on GitHub ↗

Select returns the xth integer in the bitmap. If you pass 0, you get the smallest element. Note that this function differs in convention from the Rank function which returns 1 on the smallest value.

(x uint32)

Source from the content-addressed store, hash-verified

1349// the smallest element. Note that this function differs in convention from
1350// the Rank function which returns 1 on the smallest value.
1351func (rb *Bitmap) Select(x uint32) (uint32, error) {
1352 remaining := x
1353 for i := 0; i < rb.highlowcontainer.size(); i++ {
1354 c := rb.highlowcontainer.getContainerAtIndex(i)
1355 card := uint32(c.getCardinality())
1356 if remaining >= card {
1357 remaining -= card
1358 } else {
1359 key := rb.highlowcontainer.getKeyAtIndex(i)
1360 return uint32(key)<<16 + uint32(c.selectInt(uint16(remaining))), nil
1361 }
1362 }
1363 return 0, fmt.Errorf("cannot find %dth integer in a bitmap with only %d items", x, rb.GetCardinality())
1364}
1365
1366// And computes the intersection between two bitmaps and stores the result in the current bitmap
1367func (rb *Bitmap) And(x2 *Bitmap) {

Callers 3

TestBitmapSelectCOWFunction · 0.95
TestBitmapSelectFunction · 0.95
TestSelectAfterOptimizeFunction · 0.45

Calls 6

GetCardinalityMethod · 0.95
getCardinalityMethod · 0.65
selectIntMethod · 0.65
sizeMethod · 0.45
getContainerAtIndexMethod · 0.45
getKeyAtIndexMethod · 0.45

Tested by 3

TestBitmapSelectCOWFunction · 0.76
TestBitmapSelectFunction · 0.76
TestSelectAfterOptimizeFunction · 0.36