getNextSet method

int getNextSet(
  1. int from
)

@param from first bit to check @return index of first bit that is set, starting from the given index, or size if none are set at or beyond this given index @see #getNextUnset(int)

Implementation

int getNextSet(int from) {
  if (from >= _size) {
    return _size;
  }
  int bitsOffset = from ~/ 32;
  int currentBits = _bits[bitsOffset];
  // mask off lesser bits first
  currentBits &= ~((1 << (from & 0x1F)) - 1);
  while (currentBits == 0) {
    if (++bitsOffset == _bits.length) {
      return _size;
    }
    currentBits = _bits[bitsOffset];
  }
  final result =
      (bitsOffset * 32) + MathUtils.numberOfTrailingZeros(currentBits);
  return math.min(result, _size);
}