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)
| 1349 | // the smallest element. Note that this function differs in convention from |
| 1350 | // the Rank function which returns 1 on the smallest value. |
| 1351 | func (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 |
| 1367 | func (rb *Bitmap) And(x2 *Bitmap) { |