NextSetBit returns the next set bit e.g the next int packed into the bitmaparray
(i uint)
| 1162 | |
| 1163 | // NextSetBit returns the next set bit e.g the next int packed into the bitmaparray |
| 1164 | func (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 | |
| 1186 | func (bc *bitmapContainer) NextUnsetBit(i uint) int { |
| 1187 | var ( |