if (enc.equals(EncodingType.DENSE)) { int lzr = hll.getHLLDenseRegister().getMaxRegisterValue(); bitWidth = getBitWidth(lzr); if (enc.equals(EncodingType.DENSE)) { byte[] register = hll.getHLLDenseRegister().getRegister(); bitpackHLLRegister(out, register, bitWidth); } else if (enc.equals(EncodingType.SPARSE)) { TreeMap<Integer, Byte> sparseMap = hll.getHLLSparseRegister().getSparseMap();
if (encoding.equals(EncodingType.SPARSE)) {
if (encoding.equals(EncodingType.SPARSE) && otherEncoding.equals(EncodingType.SPARSE)) { sparseRegister.merge(hll.getHLLSparseRegister()); sparseRegister = null; } else if (encoding.equals(EncodingType.DENSE) && otherEncoding.equals(EncodingType.DENSE)) { denseRegister.merge(hll.getHLLDenseRegister()); } else if (encoding.equals(EncodingType.SPARSE) && otherEncoding.equals(EncodingType.DENSE)) { denseRegister = sparseToDenseRegister(sparseRegister); denseRegister.merge(hll.getHLLDenseRegister()); sparseRegister = null; encoding = EncodingType.DENSE; } else if (encoding.equals(EncodingType.DENSE) && otherEncoding.equals(EncodingType.SPARSE)) { HLLDenseRegister otherDenseRegister = sparseToDenseRegister(hll.getHLLSparseRegister()); denseRegister.merge(otherDenseRegister);
this.invalidateCount = false; this.encoding = hllBuilder.encoding; if (encoding.equals(EncodingType.SPARSE)) { this.sparseRegister = new HLLSparseRegister(p, HLLConstants.P_PRIME_VALUE, HLLConstants.Q_PRIME_VALUE);
public void add(long hashcode) { if (encoding.equals(EncodingType.SPARSE)) { if (sparseRegister.add(hashcode)) { invalidateCount = true; } // if size of sparse map excess the threshold convert the sparse map to // dense register and switch to DENSE encoding if (sparseRegister.getSize() > encodingSwitchThreshold) { encoding = EncodingType.DENSE; denseRegister = sparseToDenseRegister(sparseRegister); sparseRegister = null; invalidateCount = true; } } else { if (denseRegister.add(hashcode)) { invalidateCount = true; } } }
@Override public boolean equals(Object obj) { if (!(obj instanceof HyperLogLog)) { return false; } HyperLogLog other = (HyperLogLog) obj; long count = estimateNumDistinctValues(); long otherCount = other.estimateNumDistinctValues(); boolean result = p == other.p && chosenHashBits == other.chosenHashBits && encoding.equals(other.encoding) && count == otherCount; if (encoding.equals(EncodingType.DENSE)) { result = result && denseRegister.equals(other.getHLLDenseRegister()); } if (encoding.equals(EncodingType.SPARSE)) { result = result && sparseRegister.equals(other.getHLLSparseRegister()); } return result; }
@Override public int hashCode() { int hashcode = 0; hashcode += 31 * p; hashcode += 31 * chosenHashBits; hashcode += encoding.hashCode(); hashcode += 31 * estimateNumDistinctValues(); if (encoding.equals(EncodingType.DENSE)) { hashcode += 31 * denseRegister.hashCode(); } if (encoding.equals(EncodingType.SPARSE)) { hashcode += 31 * sparseRegister.hashCode(); } return hashcode; }
if (encoding.equals(EncodingType.SPARSE)) { result = HyperLogLog.builder().setNumRegisterIndexBits(p) .setEncoding(EncodingType.SPARSE).build();
if (encoding.equals(EncodingType.SPARSE) && otherEncoding.equals(EncodingType.SPARSE)) { sparseRegister.merge(hll.getHLLSparseRegister()); sparseRegister = null; } else if (encoding.equals(EncodingType.DENSE) && otherEncoding.equals(EncodingType.DENSE)) { denseRegister.merge(hll.getHLLDenseRegister()); } else if (encoding.equals(EncodingType.SPARSE) && otherEncoding.equals(EncodingType.DENSE)) { denseRegister = sparseToDenseRegister(sparseRegister); denseRegister.merge(hll.getHLLDenseRegister()); sparseRegister = null; encoding = EncodingType.DENSE; } else if (encoding.equals(EncodingType.DENSE) && otherEncoding.equals(EncodingType.SPARSE)) { HLLDenseRegister otherDenseRegister = sparseToDenseRegister(hll.getHLLSparseRegister()); denseRegister.merge(otherDenseRegister);
this.invalidateCount = false; this.encoding = hllBuilder.encoding; if (encoding.equals(EncodingType.SPARSE)) { this.sparseRegister = new HLLSparseRegister(p, HLLConstants.P_PRIME_VALUE, HLLConstants.Q_PRIME_VALUE);
if (encoding.equals(EncodingType.SPARSE)) {
public void add(long hashcode) { if (encoding.equals(EncodingType.SPARSE)) { if (sparseRegister.add(hashcode)) { invalidateCount = true; } // if size of sparse map excess the threshold convert the sparse map to // dense register and switch to DENSE encoding if (sparseRegister.getSize() > encodingSwitchThreshold) { encoding = EncodingType.DENSE; denseRegister = sparseToDenseRegister(sparseRegister); sparseRegister = null; invalidateCount = true; } } else { if (denseRegister.add(hashcode)) { invalidateCount = true; } } }
@Override public boolean equals(Object obj) { if (!(obj instanceof HyperLogLog)) { return false; } HyperLogLog other = (HyperLogLog) obj; long count = estimateNumDistinctValues(); long otherCount = other.estimateNumDistinctValues(); boolean result = p == other.p && chosenHashBits == other.chosenHashBits && encoding.equals(other.encoding) && count == otherCount; if (encoding.equals(EncodingType.DENSE)) { result = result && denseRegister.equals(other.getHLLDenseRegister()); } if (encoding.equals(EncodingType.SPARSE)) { result = result && sparseRegister.equals(other.getHLLSparseRegister()); } return result; }
@Override public int hashCode() { int hashcode = 0; hashcode += 31 * p; hashcode += 31 * chosenHashBits; hashcode += encoding.hashCode(); hashcode += 31 * estimateNumDistinctValues(); if (encoding.equals(EncodingType.DENSE)) { hashcode += 31 * denseRegister.hashCode(); } if (encoding.equals(EncodingType.SPARSE)) { hashcode += 31 * sparseRegister.hashCode(); } return hashcode; }