@Test public void testPeekLength() throws IOException { HLLCounterOld hllc = new HLLCounterOld(10); HLLCounterOld copy = new HLLCounterOld(10); byte[] value = new byte[10]; for (int i = 0; i < 200000; i++) { rand1.nextBytes(value); hllc.add(value); buf.clear(); hllc.writeRegisters(buf); int len = buf.position(); buf.position(0); assertEquals(len, hllc.peekLength(buf)); copy.readRegisters(buf); assertEquals(len, buf.position()); assertEquals(hllc, copy); } buf.clear(); }
public int peekLength(ByteBuffer in) { int mark = in.position(); int len; byte scheme = in.get(); if (scheme == 0) { int size = BytesUtil.readVInt(in); int indexLen = getRegisterIndexSize(); len = in.position() - mark + (indexLen + 1) * size; } else { len = in.position() - mark + m; } in.position(mark); return len; }
HLLCounterOld implements Serializable, Comparable<HLLCounterOld> { public int peekLength(ByteBuffer in) { int mark = in.position(); int len; byte scheme = in.get(); if (scheme == 0) { int size = BytesUtil.readVInt(in); int indexLen = getRegisterIndexSize(); len = in.position() - mark + (indexLen + 1) * size; } else { len = in.position() - mark + m; } in.position(mark); return len; } }
HLLCounterOld implements Serializable, Comparable<HLLCounterOld> { public int peekLength(ByteBuffer in) { int mark = in.position(); int len; byte scheme = in.get(); if (scheme == 0) { int size = BytesUtil.readVInt(in); int indexLen = getRegisterIndexSize(); len = in.position() - mark + (indexLen + 1) * size; } else { len = in.position() - mark + m; } in.position(mark); return len; } HLLCounterOld();  HLLCounterOld(int p);  HLLCounterOld(HLLCounterOld another); private  HLLCounterOld(int p, HashFunction hashFunc); }
HLLCounterOld implements Serializable, Comparable<HLLCounterOld> { public int peekLength(ByteBuffer in) { int mark = in.position(); int len; byte scheme = in.get(); if (scheme == 0) { int size = BytesUtil.readVInt(in); int indexLen = getRegisterIndexSize(); len = in.position() - mark + (indexLen + 1) * size; } else { len = in.position() - mark + m; } in.position(mark); return len; } HLLCounterOld();  HLLCounterOld(int p);  HLLCounterOld(HLLCounterOld another); private  HLLCounterOld(int p, HashFunction hashFunc); void clear(); void add(int value); void add(String value); void add(byte[] value); void add(byte[] value, int offset, int length); void merge(HLLCounterOld another); long getCountEstimate(); int getPrecision(); double getErrorRate(); @Override String toString(); void writeRegisters(final ByteBuffer out); void readRegisters(ByteBuffer in); int peekLength(ByteBuffer in); int maxLength(); @Override int hashCode(); @Override boolean equals(Object obj); @Override int compareTo(HLLCounterOld o); static void main(String[] args); static void writeUnsigned(int num, int size, ByteBuffer out); static int readUnsigned(ByteBuffer in, int size); }
HLLCounterOld implements Serializable, Comparable<HLLCounterOld> { public int peekLength(ByteBuffer in) { int mark = in.position(); int len; byte scheme = in.get(); if (scheme == 0) { int size = BytesUtil.readVInt(in); int indexLen = getRegisterIndexSize(); len = in.position() - mark + (indexLen + 1) * size; } else { len = in.position() - mark + m; } in.position(mark); return len; } HLLCounterOld();  HLLCounterOld(int p);  HLLCounterOld(HLLCounterOld another); private  HLLCounterOld(int p, HashFunction hashFunc); void clear(); void add(int value); void add(String value); void add(byte[] value); void add(byte[] value, int offset, int length); void merge(HLLCounterOld another); long getCountEstimate(); int getPrecision(); double getErrorRate(); @Override String toString(); void writeRegisters(final ByteBuffer out); void readRegisters(ByteBuffer in); int peekLength(ByteBuffer in); int maxLength(); @Override int hashCode(); @Override boolean equals(Object obj); @Override int compareTo(HLLCounterOld o); static void main(String[] args); static void writeUnsigned(int num, int size, ByteBuffer out); static int readUnsigned(ByteBuffer in, int size);  }