@Test public void testNextSetBit() { BitSet bitSet = new BitSet(NUM_BITS); assertEquals(-1, bitSet.nextSetBit(0)); bitSet.set(3); assertEquals(3, bitSet.nextSetBit(0)); assertEquals(3, bitSet.nextSetBit(2)); assertEquals(3, bitSet.nextSetBit(3)); assertEquals(-1, bitSet.nextSetBit(4)); bitSet.set(5); bitSet.set(7); assertEquals(5, bitSet.nextSetBit(4)); assertEquals(5, bitSet.nextSetBit(5)); assertEquals(7, bitSet.nextSetBit(6)); bitSet.set(64); assertEquals(64, bitSet.nextSetBit(8)); assertEquals(64, bitSet.nextSetBit(63)); assertEquals(64, bitSet.nextSetBit(64)); assertEquals(-1, bitSet.nextSetBit(65)); assertEquals(-1, bitSet.nextSetBit(NUM_BITS - 1)); }
public int nextSetBit(int index) { int offset = index >>> 6; int offsetInLong = index & 0x3F; long mask = ~((1L << offsetInLong) - 1); while (offset < bits.length && (bits[offset] & mask) == 0) { offset++; mask = -1L; } if (offset == bits.length) { return -1; } return (offset << 6) + Long.numberOfTrailingZeros(bits[offset] & mask); }
BitSet implements Serializable, Cloneable { public int nextSetBit(int index) { int offset = index >>> 6; int offsetInLong = index & 0x3F; long mask = ~((1L << offsetInLong) - 1); while (offset < bits.length && (bits[offset] & mask) == 0) { offset++; mask = -1L; } if (offset == bits.length) { return -1; } return (offset << 6) + Long.numberOfTrailingZeros(bits[offset] & mask); } }
BitSet implements Serializable, Cloneable { public int nextSetBit(int index) { int offset = index >>> 6; int offsetInLong = index & 0x3F; long mask = ~((1L << offsetInLong) - 1); while (offset < bits.length && (bits[offset] & mask) == 0) { offset++; mask = -1L; } if (offset == bits.length) { return -1; } return (offset << 6) + Long.numberOfTrailingZeros(bits[offset] & mask); } BitSet(int numBits); private  BitSet(long[] bits); }
BitSet implements Serializable, Cloneable { public int nextSetBit(int index) { int offset = index >>> 6; int offsetInLong = index & 0x3F; long mask = ~((1L << offsetInLong) - 1); while (offset < bits.length && (bits[offset] & mask) == 0) { offset++; mask = -1L; } if (offset == bits.length) { return -1; } return (offset << 6) + Long.numberOfTrailingZeros(bits[offset] & mask); } BitSet(int numBits); private  BitSet(long[] bits); boolean get(int index); void set(int index); void set(int from, int to); void clear(int index); void clear(); int cardinality(); int nextSetBit(int index); @Override BitSet clone(); @Override int hashCode(); @Override boolean equals(Object o); @Override String toString(); }
BitSet implements Serializable, Cloneable { public int nextSetBit(int index) { int offset = index >>> 6; int offsetInLong = index & 0x3F; long mask = ~((1L << offsetInLong) - 1); while (offset < bits.length && (bits[offset] & mask) == 0) { offset++; mask = -1L; } if (offset == bits.length) { return -1; } return (offset << 6) + Long.numberOfTrailingZeros(bits[offset] & mask); } BitSet(int numBits); private  BitSet(long[] bits); boolean get(int index); void set(int index); void set(int from, int to); void clear(int index); void clear(); int cardinality(); int nextSetBit(int index); @Override BitSet clone(); @Override int hashCode(); @Override boolean equals(Object o); @Override String toString();  }