getNextUnset method
@param from index to start looking for unset bit
@return index of next unset bit, or size
if none are unset until the end
@see #getNextSet(int)
Implementation
int getNextUnset(int from) {
if (from >= _size) {
return _size;
}
int bitsOffset = from ~/ 32;
int currentBits = (~_bits[bitsOffset]).toUnsigned(32);
// mask off lesser bits first
currentBits &= (~((1 << (from & 0x1F)) - 1)).toUnsigned(32);
while (currentBits == 0) {
if (++bitsOffset == _bits.length) {
return _size;
}
currentBits = (~_bits[bitsOffset]).toUnsigned(32);
}
final result =
(bitsOffset * 32) + MathUtils.numberOfTrailingZeros(currentBits);
return math.min(result, _size);
}