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

Method NextSetBit

bitmapcontainer.go:1164–1184  ·  view source on GitHub ↗

NextSetBit returns the next set bit e.g the next int packed into the bitmaparray

(i uint)

Source from the content-addressed store, hash-verified

1162
1163// NextSetBit returns the next set bit e.g the next int packed into the bitmaparray
1164func (bc *bitmapContainer) NextSetBit(i uint) int {
1165 var (
1166 x = i / 64
1167 length = uint(len(bc.bitmap))
1168 )
1169 if x >= length {
1170 return -1
1171 }
1172 w := bc.bitmap[x]
1173 w = w >> (i % 64)
1174 if w != 0 {
1175 return int(i) + countTrailingZeros(w)
1176 }
1177 x++
1178 for ; x < length; x++ {
1179 if bc.bitmap[x] != 0 {
1180 return int(x*64) + countTrailingZeros(bc.bitmap[x])
1181 }
1182 }
1183 return -1
1184}
1185
1186func (bc *bitmapContainer) NextUnsetBit(i uint) int {
1187 var (

Callers 8

iterateMethod · 0.95
nextValueMethod · 0.95
initMethod · 0.80
nextMethod · 0.80
advanceIfNeededMethod · 0.80
validateFunction · 0.80
TestBitmapNextSetFunction · 0.80

Calls 1

countTrailingZerosFunction · 0.70

Tested by 2

validateFunction · 0.64
TestBitmapNextSetFunction · 0.64