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

Method PreviousAbsentValue

roaring.go:2339–2392  ·  view source on GitHub ↗

PreviousAbsentValue returns the previous 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

2337// a performance-sensitive loop: prefer iterators if
2338// performance is a concern.
2339func (rb *Bitmap) PreviousAbsentValue(target uint32) int64 {
2340 originalKey := highbits(target)
2341 query := lowbits(target)
2342 var prevValue int64
2343 prevValue = -1
2344
2345 containerIndex := rb.highlowcontainer.advanceUntil(originalKey, -1)
2346
2347 if containerIndex == rb.highlowcontainer.size() {
2348 // if we are here it means no container found, just return the target
2349 return int64(target)
2350 }
2351
2352 if containerIndex == -1 {
2353 // if we are here it means no container found, just return the target
2354 return int64(target)
2355 }
2356
2357 containerKey := rb.highlowcontainer.getKeyAtIndex(containerIndex)
2358 keyspace := uint32(containerKey) << 16
2359 if target < keyspace {
2360 // target is less than the start of the keyspace start
2361 // that means target cannot be in the keyspace
2362 return int64(target)
2363 }
2364
2365 container := rb.highlowcontainer.getContainer(containerKey)
2366 prevValue = int64(container.previousAbsentValue(query))
2367 for {
2368 if prevValue != -1 {
2369 return int64(combineLoHi32(uint32(prevValue), keyspace))
2370 }
2371
2372 if containerIndex == 0 {
2373 val, err := container.safeMinimum()
2374 if err == nil {
2375 // OR panic, Java panics
2376 return -1
2377 }
2378 return int64(val) - 1
2379 }
2380 containerIndex--
2381 nextContainerKey := rb.highlowcontainer.getKeyAtIndex(containerIndex)
2382 if nextContainerKey < containerKey-1 {
2383 // There is a gap between keys, eg missing container
2384 // Just decrement the current key and shift to get HoB of the missing container
2385 return (int64(containerKey) << 16) - 1
2386 }
2387 containerKey = nextContainerKey
2388 container = rb.highlowcontainer.getContainer(containerKey)
2389 highestPossible16 := (1 << 16) - 1
2390 prevValue = int64(container.previousAbsentValue(uint16(highestPossible16)))
2391 }
2392}
2393
2394// FlipInt calls Flip after casting the parameters (convenience method)
2395func FlipInt(bm *Bitmap, rangeStart, rangeEnd int) *Bitmap {

Callers 1

TestNextAndPreviousValueFunction · 0.80

Calls 9

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

Tested by 1

TestNextAndPreviousValueFunction · 0.64