@Test public void testPeekLength() throws IOException { HLLCounter hllc = new HLLCounter(10); HLLCounter copy = new HLLCounter(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; }
HLLCounter implements Serializable, Comparable<HLLCounter> { 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; } }
HLLCounter implements Serializable, Comparable<HLLCounter> { 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; } HLLCounter();  HLLCounter(int p);  HLLCounter(int p, HashFunction hashFunc);  HLLCounter(HLLCounter another);  HLLCounter(int p, RegisterType type);   HLLCounter(int p, RegisterType type, HashFunction hashFunc); }
HLLCounter implements Serializable, Comparable<HLLCounter> { 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; } HLLCounter();  HLLCounter(int p);  HLLCounter(int p, HashFunction hashFunc);  HLLCounter(HLLCounter another);  HLLCounter(int p, RegisterType type);   HLLCounter(int p, RegisterType type, HashFunction hashFunc); boolean isDense(int size); void add(int value); void add(String value); void add(byte[] value); void add(byte[] value, int offset, int length); void addHashDirectly(long hash); void merge(HLLCounter another); long getCountEstimate(); int getPrecision(); double getErrorRate(); @Override String toString(); static void main(String[] args); Register getRegister(); void clear(); void writeRegisters(final ByteBuffer out); void readRegisters(ByteBuffer in); int peekLength(ByteBuffer in); int maxLength(); int getRegisterIndexSize(); @Override int hashCode(); @Override boolean equals(Object obj); @Override int compareTo(HLLCounter o); static void writeUnsigned(int num, int size, ByteBuffer out); static int readUnsigned(ByteBuffer in, int size); RegisterType getRegisterType(); }
HLLCounter implements Serializable, Comparable<HLLCounter> { 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; } HLLCounter();  HLLCounter(int p);  HLLCounter(int p, HashFunction hashFunc);  HLLCounter(HLLCounter another);  HLLCounter(int p, RegisterType type);   HLLCounter(int p, RegisterType type, HashFunction hashFunc); boolean isDense(int size); void add(int value); void add(String value); void add(byte[] value); void add(byte[] value, int offset, int length); void addHashDirectly(long hash); void merge(HLLCounter another); long getCountEstimate(); int getPrecision(); double getErrorRate(); @Override String toString(); static void main(String[] args); Register getRegister(); void clear(); void writeRegisters(final ByteBuffer out); void readRegisters(ByteBuffer in); int peekLength(ByteBuffer in); int maxLength(); int getRegisterIndexSize(); @Override int hashCode(); @Override boolean equals(Object obj); @Override int compareTo(HLLCounter o); static void writeUnsigned(int num, int size, ByteBuffer out); static int readUnsigned(ByteBuffer in, int size); RegisterType getRegisterType();  }