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

Method NextAbsentValue

roaring.go:2287–2333  ·  view source on GitHub ↗

NextAbsentValue returns the next largest missing 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

2285// a performance-sensitive loop: prefer iterators if
2286// performance is a concern.
2287func (rb *Bitmap) NextAbsentValue(target uint32) int64 {
2288 originalKey := highbits(target)
2289 query := lowbits(target)
2290 var nextValue int64
2291 nextValue = -1
2292
2293 containerIndex := rb.highlowcontainer.advanceUntil(originalKey, -1)
2294 if containerIndex == rb.highlowcontainer.size() {
2295 // if we are here it means no container found, just return the target
2296 return int64(target)
2297 }
2298
2299 containerKey := rb.highlowcontainer.getKeyAtIndex(containerIndex)
2300
2301 keyspace := uint32(containerKey) << 16
2302 if target < keyspace {
2303 // target is less than the start of the keyspace start
2304 // that means target cannot be in the keyspace
2305 return int64(target)
2306 }
2307
2308 container := rb.highlowcontainer.getContainer(containerKey)
2309 nextValue = int64(container.nextAbsentValue(query))
2310 for {
2311 if nextValue != (1 << 16) {
2312 return int64(combineLoHi32(uint32(nextValue), keyspace))
2313 }
2314
2315 if containerIndex == rb.highlowcontainer.size()-1 {
2316 val, err := container.safeMaximum()
2317 if err == nil {
2318 return -1
2319 }
2320 return int64(val) + 1
2321 }
2322 containerIndex++
2323 nextContainerKey := rb.highlowcontainer.getKeyAtIndex(containerIndex)
2324 if containerKey < nextContainerKey {
2325 // There is a gap between keys
2326 // Just increment the current key and shift to get HoB
2327 return int64(containerKey+1) << 16
2328 }
2329 containerKey = nextContainerKey
2330 container = rb.highlowcontainer.getContainer(containerKey)
2331 nextValue = int64(container.nextAbsentValue(0))
2332 }
2333}
2334
2335// PreviousAbsentValue returns the previous largest missing value in the bitmap, or -1
2336// 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
nextAbsentValueMethod · 0.65
safeMaximumMethod · 0.65
advanceUntilMethod · 0.45
sizeMethod · 0.45
getKeyAtIndexMethod · 0.45
getContainerMethod · 0.45

Tested by 1

TestNextAndPreviousValueFunction · 0.64