MCPcopy
hub / github.com/RoaringBitmap/roaring / NextValue

Method NextValue

roaring.go:2198–2229  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

2196// a performance-sensitive loop: prefer iterators if
2197// performance is a concern.
2198func (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

Callers 1

TestNextAndPreviousValueFunction · 0.80

Calls 9

combineLoHi32Function · 0.85
highbitsFunction · 0.70
lowbitsFunction · 0.70
safeMinimumMethod · 0.65
nextValueMethod · 0.65
advanceUntilMethod · 0.45
sizeMethod · 0.45
getKeyAtIndexMethod · 0.45
getContainerMethod · 0.45

Tested by 1

TestNextAndPreviousValueFunction · 0.64