@Test public void mergeTest() throws IOException { double error = 0; int n = 100; for (int i = 0; i < n; i += 10) { double e = merge(i); error += e; } System.out.println("Total average error is " + error / n); System.out.println(" errorRateCount1 is " + errorCount1 + "!"); System.out.println(" errorRateCount2 is " + errorCount2 + "!"); System.out.println(" errorRateCount3 is " + errorCount3 + "!"); Assert.assertTrue(errorCount1 <= n * 0.30); Assert.assertTrue(errorCount2 <= n * 0.05); Assert.assertTrue(errorCount3 <= n * 0.02); }
public void merge(HLLCounter another) { assert this.p == another.p; assert this.hashFunc == another.hashFunc; switch (register.getRegisterType()) { case SINGLE_VALUE: switch (another.getRegisterType()) { case SINGLE_VALUE: if (register.getSize() > 0 && another.register.getSize() > 0) { register = ((SingleValueRegister) register).toSparse(); } else { SingleValueRegister sr = (SingleValueRegister) another.register; if (sr.getSize() > 0) register.set(sr.getSingleValuePos(), sr.getValue()); return; } break; case SPARSE: register = ((SingleValueRegister) register).toSparse(); break; case DENSE: register = ((SingleValueRegister) register).toDense(this.p); break; default: break; } break; case SPARSE: if (another.getRegisterType() == RegisterType.DENSE) { register = ((SparseRegister) register).toDense(p); } break; default: break; } register.merge(another.register); toDenseIfNeeded(); }
HLLCounter implements Serializable, Comparable<HLLCounter> { public void merge(HLLCounter another) { assert this.p == another.p; assert this.hashFunc == another.hashFunc; switch (register.getRegisterType()) { case SINGLE_VALUE: switch (another.getRegisterType()) { case SINGLE_VALUE: if (register.getSize() > 0 && another.register.getSize() > 0) { register = ((SingleValueRegister) register).toSparse(); } else { SingleValueRegister sr = (SingleValueRegister) another.register; if (sr.getSize() > 0) register.set(sr.getSingleValuePos(), sr.getValue()); return; } break; case SPARSE: register = ((SingleValueRegister) register).toSparse(); break; case DENSE: register = ((SingleValueRegister) register).toDense(this.p); break; default: break; } break; case SPARSE: if (another.getRegisterType() == RegisterType.DENSE) { register = ((SparseRegister) register).toDense(p); } break; default: break; } register.merge(another.register); toDenseIfNeeded(); } }
HLLCounter implements Serializable, Comparable<HLLCounter> { public void merge(HLLCounter another) { assert this.p == another.p; assert this.hashFunc == another.hashFunc; switch (register.getRegisterType()) { case SINGLE_VALUE: switch (another.getRegisterType()) { case SINGLE_VALUE: if (register.getSize() > 0 && another.register.getSize() > 0) { register = ((SingleValueRegister) register).toSparse(); } else { SingleValueRegister sr = (SingleValueRegister) another.register; if (sr.getSize() > 0) register.set(sr.getSingleValuePos(), sr.getValue()); return; } break; case SPARSE: register = ((SingleValueRegister) register).toSparse(); break; case DENSE: register = ((SingleValueRegister) register).toDense(this.p); break; default: break; } break; case SPARSE: if (another.getRegisterType() == RegisterType.DENSE) { register = ((SparseRegister) register).toDense(p); } break; default: break; } register.merge(another.register); toDenseIfNeeded(); } 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 void merge(HLLCounter another) { assert this.p == another.p; assert this.hashFunc == another.hashFunc; switch (register.getRegisterType()) { case SINGLE_VALUE: switch (another.getRegisterType()) { case SINGLE_VALUE: if (register.getSize() > 0 && another.register.getSize() > 0) { register = ((SingleValueRegister) register).toSparse(); } else { SingleValueRegister sr = (SingleValueRegister) another.register; if (sr.getSize() > 0) register.set(sr.getSingleValuePos(), sr.getValue()); return; } break; case SPARSE: register = ((SingleValueRegister) register).toSparse(); break; case DENSE: register = ((SingleValueRegister) register).toDense(this.p); break; default: break; } break; case SPARSE: if (another.getRegisterType() == RegisterType.DENSE) { register = ((SparseRegister) register).toDense(p); } break; default: break; } register.merge(another.register); toDenseIfNeeded(); } 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 void merge(HLLCounter another) { assert this.p == another.p; assert this.hashFunc == another.hashFunc; switch (register.getRegisterType()) { case SINGLE_VALUE: switch (another.getRegisterType()) { case SINGLE_VALUE: if (register.getSize() > 0 && another.register.getSize() > 0) { register = ((SingleValueRegister) register).toSparse(); } else { SingleValueRegister sr = (SingleValueRegister) another.register; if (sr.getSize() > 0) register.set(sr.getSingleValuePos(), sr.getValue()); return; } break; case SPARSE: register = ((SingleValueRegister) register).toSparse(); break; case DENSE: register = ((SingleValueRegister) register).toDense(this.p); break; default: break; } break; case SPARSE: if (another.getRegisterType() == RegisterType.DENSE) { register = ((SparseRegister) register).toDense(p); } break; default: break; } register.merge(another.register); toDenseIfNeeded(); } 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();  }