BytesRank1OnlySuccinctBitVector implements Externalizable, SuccinctBitVector { @Override public int rank1(int pos){ int cn = pos / CACHE_WIDTH; if((pos + 1) % CACHE_WIDTH == 0) return countCache1[cn]; if(cn > 0){ int ret = countCache1[cn - 1]; int n = pos / 8; for(int i = (cn * (CACHE_WIDTH / 8)); i < n; i++){ ret += BITCOUNTS1[bytes[i] & 0xff]; } return ret + BITCOUNTS1[bytes[n] & MASKS[pos % 8]]; } else{ int ret = 0; int n = pos / 8; for(int i = 0; i < n; i++){ ret += BITCOUNTS1[bytes[i] & 0xff]; } return ret + BITCOUNTS1[bytes[n] & MASKS[pos % 8]]; } } BytesRank1OnlySuccinctBitVector();  BytesRank1OnlySuccinctBitVector(int initialCapacity);  BytesRank1OnlySuccinctBitVector(byte[] bytes, int bits);  BytesRank1OnlySuccinctBitVector(byte[] bytes, int size, int[] countCache1); byte[] getBytes(); int[] getCountCache1(); @Override String toString(); @Override boolean get(int pos); @Override boolean isZero(int pos); @Override boolean isOne(int pos); @Override int size(); void trimToSize(); void append1(); void append0(); @Override int select0(int num); @Override int next0(int count); @Override int select1(int num); @Override int rank0(int pos); @Override int rank1(int pos); void save(OutputStream os); void load(InputStream is); @Override void readExternal(ObjectInput in); @Override void writeExternal(ObjectOutput out);  }
@Test public void test_2() throws Exception{ BytesRank1OnlySuccinctBitVector bv = new BytesRank1OnlySuccinctBitVector( new byte[]{127, -12, -102, -1, -6, 95, -1, -33, -128}, 65 ); Assert.assertEquals(52, bv.rank1(64)); }
@Test public void test_from_bytes_rank_1() throws Exception{ SuccinctBitVector sbv = new BytesRank1OnlySuccinctBitVector( new byte[]{0x01, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte)0x80}, 68 ); Assert.assertEquals(0, sbv.rank1(4)); Assert.assertEquals(1, sbv.rank1(8)); Assert.assertEquals(6, sbv.rank1(15)); Assert.assertEquals(7, sbv.rank1(64)); }