Select returns the xth integer in the bitmap
(x uint64)
| 412 | |
| 413 | // Select returns the xth integer in the bitmap |
| 414 | func (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 |
| 438 | func (rb *Bitmap) And(x2 *Bitmap) { |