@Test public void testCardinality() { BitSet bitSet = new BitSet(NUM_BITS); assertEquals(0, bitSet.cardinality()); bitSet.set(0); assertEquals(1, bitSet.cardinality()); bitSet.set(0); assertEquals(1, bitSet.cardinality()); bitSet.set(1); assertEquals(2, bitSet.cardinality()); bitSet.set(63); assertEquals(3, bitSet.cardinality()); bitSet.set(64); assertEquals(4, bitSet.cardinality()); bitSet.set(NUM_BITS - 1); assertEquals(5, bitSet.cardinality()); bitSet.clear(0); assertEquals(4, bitSet.cardinality()); }
public int cardinality() { int sum = 0; for (long l : bits) { sum += Long.bitCount(l); } return sum; }
BitSet implements Serializable, Cloneable { public int cardinality() { int sum = 0; for (long l : bits) { sum += Long.bitCount(l); } return sum; } }
BitSet implements Serializable, Cloneable { public int cardinality() { int sum = 0; for (long l : bits) { sum += Long.bitCount(l); } return sum; } BitSet(int numBits); private  BitSet(long[] bits); }
BitSet implements Serializable, Cloneable { public int cardinality() { int sum = 0; for (long l : bits) { sum += Long.bitCount(l); } return sum; } 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 cardinality() { int sum = 0; for (long l : bits) { sum += Long.bitCount(l); } return sum; } 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();  }