NextValue returns the next largest value in the bitmap, or -1 if none is present. This function should not be used inside a performance-sensitive loop: prefer iterators if performance is a concern.
(target uint32)
| 2196 | // a performance-sensitive loop: prefer iterators if |
| 2197 | // performance is a concern. |
| 2198 | func (rb *Bitmap) NextValue(target uint32) int64 { |
| 2199 | originalKey := highbits(target) |
| 2200 | query := lowbits(target) |
| 2201 | var nextValue int64 |
| 2202 | nextValue = -1 |
| 2203 | containerIndex := rb.highlowcontainer.advanceUntil(originalKey, -1) |
| 2204 | for containerIndex < rb.highlowcontainer.size() && nextValue == -1 { |
| 2205 | containerKey := rb.highlowcontainer.getKeyAtIndex(containerIndex) |
| 2206 | container := rb.highlowcontainer.getContainer(containerKey) |
| 2207 | // if containerKey > orginalKey then we are past the container which mapped to the orignal key |
| 2208 | // in that case we can just return the minimum from that container |
| 2209 | var responseBit int64 |
| 2210 | if containerKey > originalKey { |
| 2211 | bit, err := container.safeMinimum() |
| 2212 | if err == nil { |
| 2213 | responseBit = -1 |
| 2214 | } |
| 2215 | responseBit = int64(bit) |
| 2216 | } else { |
| 2217 | responseBit = int64(container.nextValue(query)) |
| 2218 | } |
| 2219 | |
| 2220 | if responseBit == -1 { |
| 2221 | nextValue = -1 |
| 2222 | } else { |
| 2223 | nextValue = int64(combineLoHi32(uint32(responseBit), uint32(containerKey))) |
| 2224 | } |
| 2225 | containerIndex++ |
| 2226 | } |
| 2227 | |
| 2228 | return nextValue |
| 2229 | } |
| 2230 | |
| 2231 | // PreviousValue returns the previous largest value in the bitmap, or -1 |
| 2232 | // if none is present. This function should not be used inside |