Rank returns the number of integers that are smaller or equal to x (Rank(infinity) would be GetCardinality()). If you pass the smallest value, you get the value 1. If you pass a value that is smaller than the smallest value, you get 0. Note that this function differs in convention from the Select fu
(x uint32)
| 1257 | // value, you get 0. Note that this function differs in convention from the Select function since it |
| 1258 | // return 1 and not 0 on the smallest value. |
| 1259 | func (rb *Bitmap) Rank(x uint32) uint64 { |
| 1260 | size := uint64(0) |
| 1261 | for i := 0; i < rb.highlowcontainer.size(); i++ { |
| 1262 | key := rb.highlowcontainer.getKeyAtIndex(i) |
| 1263 | if key > highbits(x) { |
| 1264 | return size |
| 1265 | } |
| 1266 | if key < highbits(x) { |
| 1267 | size += uint64(rb.highlowcontainer.getContainerAtIndex(i).getCardinality()) |
| 1268 | } else { |
| 1269 | return size + uint64(rb.highlowcontainer.getContainerAtIndex(i).rank(lowbits(x))) |
| 1270 | } |
| 1271 | } |
| 1272 | return size |
| 1273 | } |
| 1274 | |
| 1275 | // CardinalityInRange returns the number of integers that are in the half-open range [start, end). |
| 1276 | // It is equivalent to Rank(uint32(end-1)) - Rank(uint32(start-1)) for start > 0, |