public int size() { // the number of bytes that can fit without using "more" memory return bitIndex(array.length()); }
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 length() { int last = trimToSize(array); if (last == -1) { return 0; } // compute the position of the leftmost bit's index int offsets[] = { 16, 8, 4, 2, 1 }; int bitMasks[] = { 0xffff0000, 0xff00, 0xf0, 0xc, 0x2 }; int position = bitIndex(last) + 1; int word = getWord(array, last); for (int i = 0; i < offsets.length; i++) { if ((word & bitMasks[i]) != 0) { word >>>= offsets[i]; position += offsets[i]; } } return position; }
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)); };
if ((bitIndex(newLength)) - fromIndex != 0) { maskOutWord(array, newLength - 1, bitOffset(fromIndex), 32);