/** Return the index of the least bit position >= x that is set. * If none are set, returns -1. This provides a nice way to iterate * over the members of a bit set: * <pre> * for (int i = bits.nextBit(0); i>=0; i = bits.nextBit(i+1)) ... * </pre> */ public int nextBit(int x) { int windex = x >>> wordshift; if (windex >= bits.length) return -1; int word = bits[windex] & ~((1 << (x & wordmask))-1); while (true) { if (word != 0) return (windex << wordshift) + trailingZeroBits(word); windex++; if (windex >= bits.length) return -1; word = bits[windex]; } }
/** Return the index of the least bit position >= x that is set. * If none are set, returns -1. This provides a nice way to iterate * over the members of a bit set: * <pre> * for (int i = bits.nextBit(0); i>=0; i = bits.nextBit(i+1)) ... * </pre> */ public int nextBit(int x) { int windex = x >>> wordshift; if (windex >= bits.length) return -1; int word = bits[windex] & ~((1 << (x & wordmask))-1); while (true) { if (word != 0) return (windex << wordshift) + trailingZeroBits(word); windex++; if (windex >= bits.length) return -1; word = bits[windex]; } }
/** Return the index of the least bit position ≥ x that is set. * If none are set, returns -1. This provides a nice way to iterate * over the members of a bit set: * <pre>{@code * for (int i = bits.nextBit(0); i>=0; i = bits.nextBit(i+1)) ... * }</pre> */ public int nextBit(int x) { Assert.check(currentState != BitsState.UNKNOWN); int windex = x >>> wordshift; if (windex >= bits.length) { return -1; } int word = bits[windex] & ~((1 << (x & wordmask))-1); while (true) { if (word != 0) { return (windex << wordshift) + trailingZeroBits(word); } windex++; if (windex >= bits.length) { return -1; } word = bits[windex]; } }
/** Return the index of the least bit position ≥ x that is set. * If none are set, returns -1. This provides a nice way to iterate * over the members of a bit set: * <pre>{@code * for (int i = bits.nextBit(0); i>=0; i = bits.nextBit(i+1)) ... * }</pre> */ public int nextBit(int x) { Assert.check(currentState != BitsState.UNKNOWN); int windex = x >>> wordshift; if (windex >= bits.length) { return -1; } int word = bits[windex] & ~((1 << (x & wordmask))-1); while (true) { if (word != 0) { return (windex << wordshift) + trailingZeroBits(word); } windex++; if (windex >= bits.length) { return -1; } word = bits[windex]; } }