HyperLogLogEstimator implements UniqueCountEstimator<Sketch<?>> { @Override public long estimateCount(Sketch<?> sketch) { if (sketch instanceof NormalSketch) { return estimateCount((NormalSketch) sketch); } else { return estimateCount((SparseSketch) sketch); } } HyperLogLogEstimator(int precision);  HyperLogLogEstimator(); @Override long estimateCount(Sketch<?> sketch);  }
@Test public void requireThatEstimateIsReasonableForFullNormalSketch() { HyperLogLogEstimator estimator = new HyperLogLogEstimator(10); NormalSketch sketch = new NormalSketch(10); Arrays.fill(sketch.data(), (byte) 23); long estimate = estimator.estimateCount(sketch); assertTrue(estimate > 6_000_000_000l); }
@Test public void requireThatEstimateIsCorrectForSparseSketch() { SparseSketch sketch = new SparseSketch(); HyperLogLogEstimator estimator = new HyperLogLogEstimator(10); long estimate = estimator.estimateCount(sketch); assertEquals(0, estimate); for (int i = 1; i <= HyperLogLog.SPARSE_SKETCH_CONVERSION_THRESHOLD; i++) { sketch.aggregate(i); estimate = estimator.estimateCount(sketch); assertEquals(i, estimate); } }