Rank returns the number of integers that are smaller or equal to x (Rank(infinity) would be GetCardinality())
(x uint64)
| 395 | |
| 396 | // Rank returns the number of integers that are smaller or equal to x (Rank(infinity) would be GetCardinality()) |
| 397 | func (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 |
| 414 | func (rb *Bitmap) Select(x uint64) (uint64, error) { |