public void clear(int bitIndex) { checkIndex(bitIndex); clear(array, bitIndex); }
public boolean get(int bitIndex) { checkIndex(bitIndex); return get(array, bitIndex); }
public void set(int bitIndex) { checkIndex(bitIndex); set(array, bitIndex); }
public void flip(int bitIndex) { checkIndex(bitIndex); flip(array, bitIndex); }
public int nextClearBit(int fromIndex) { checkIndex(fromIndex); int index = wordIndex(fromIndex); // special case for first index int fromBit = fromIndex - (bitIndex(index)); int word = getWord(array, index); for (int i = fromBit; i < 32; i++) { if ((word & (1 << i)) == 0) { return (bitIndex(index)) + i; } } // loop through the rest while (true) { index++; word = getWord(array, index); if (word != 0xffffffff) { return (bitIndex(index)) + Integer.numberOfTrailingZeros(~word); } } }
public int nextSetBit(int fromIndex) { checkIndex(fromIndex); int index = wordIndex(fromIndex); // check the current word int word = getWord(array, index); if (word != 0) { for (int i = bitOffset(fromIndex); i < 32; i++) { if ((word & (1 << i)) != 0) { return (bitIndex(index)) + i; } } } index++; // find the next set word trimToSize(array); index = nextSetWord(array, index); if (index == -1) { return -1; } // return the next set bit return (bitIndex(index)) + Integer.numberOfTrailingZeros(array.get(index)); };