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

Method Select

roaring64/roaring64.go:414–435  ·  view source on GitHub ↗

Select returns the xth integer in the bitmap

(x uint64)

Source from the content-addressed store, hash-verified

412
413// Select returns the xth integer in the bitmap
414func (rb *Bitmap) Select(x uint64) (uint64, error) {
415 cardinality := rb.GetCardinality()
416 if cardinality <= x {
417 return 0, fmt.Errorf("can't find %dth integer in a bitmap with only %d items", x, cardinality)
418 }
419
420 remaining := x
421 for i := 0; i < rb.highlowcontainer.size(); i++ {
422 c := rb.highlowcontainer.getContainerAtIndex(i)
423 if bitmapSize := c.GetCardinality(); remaining >= bitmapSize {
424 remaining -= bitmapSize
425 } else {
426 key := rb.highlowcontainer.getKeyAtIndex(i)
427 selected, err := c.Select(uint32(remaining))
428 if err != nil {
429 return 0, err
430 }
431 return uint64(key)<<32 + uint64(selected), nil
432 }
433 }
434 return 0, fmt.Errorf("can't find %dth integer in a bitmap with only %d items", x, cardinality)
435}
436
437// And computes the intersection between two bitmaps and stores the result in the current bitmap
438func (rb *Bitmap) And(x2 *Bitmap) {

Callers 3

TestBitmapSelectCOWFunction · 0.95
TestBitmapSelectFunction · 0.95
Test64BitValuesFunction · 0.45

Calls 4

GetCardinalityMethod · 0.95
sizeMethod · 0.45
getContainerAtIndexMethod · 0.45
getKeyAtIndexMethod · 0.45

Tested by 3

TestBitmapSelectCOWFunction · 0.76
TestBitmapSelectFunction · 0.76
Test64BitValuesFunction · 0.36