BytesRank0OnlySuccinctBitVector implements Externalizable, SuccinctBitVector { public int rank0(int pos){ int cn = pos / CACHE_WIDTH; if((pos + 1) % CACHE_WIDTH == 0) return countCache0[cn]; int ret = (cn > 0) ? ret = countCache0[cn - 1] : 0; int n = pos / 8; for(int i = (cn * (CACHE_WIDTH / 8)); i < n; i++){ ret += BITCOUNTS0[vector[i] & 0xff]; } return ret + BITCOUNTS0[(vector[n] | ~MASKS[pos % 8]) & 0xff]; } BytesRank0OnlySuccinctBitVector();  BytesRank0OnlySuccinctBitVector(int initialCapacity);  BytesRank0OnlySuccinctBitVector(byte[] bytes, int bits);  BytesRank0OnlySuccinctBitVector(byte[] vector, int size, int[] countCache0); byte[] getVector(); int[] getCountCache0(); @Override String toString(); @Override boolean get(int pos); boolean isZero(int pos); @Override boolean isOne(int pos); int size(); void trimToSize(); void append1(); void append0(); @Override int select0(int num); @Override int next0(int count); @Override int select1(int num); int rank0(int pos); @Override int rank1(int pos); @Override void readExternal(ObjectInput in); @Override void writeExternal(ObjectOutput out);  }
@Test public void test2() throws Exception{ BytesRank0OnlySuccinctBitVector bv = new BytesRank0OnlySuccinctBitVector( new byte[]{0x2d, 0x3f}, 16); Assert.assertEquals(1, bv.rank0(0)); Assert.assertEquals(2, bv.rank0(1)); Assert.assertEquals(2, bv.rank0(2)); Assert.assertEquals(3, bv.rank0(3)); Assert.assertEquals(3, bv.rank0(4)); Assert.assertEquals(3, bv.rank0(5)); Assert.assertEquals(4, bv.rank0(6)); Assert.assertEquals(4, bv.rank0(7)); Assert.assertEquals(5, bv.rank0(8)); Assert.assertEquals(6, bv.rank0(9)); Assert.assertEquals(6, bv.rank0(10)); Assert.assertEquals(6, bv.rank0(11)); Assert.assertEquals(6, bv.rank0(12)); Assert.assertEquals(6, bv.rank0(13)); Assert.assertEquals(6, bv.rank0(14)); Assert.assertEquals(6, bv.rank0(15)); try{ bv.rank0(16); Assert.fail(); } catch(ArrayIndexOutOfBoundsException e){ } }