private long estimateCount(NormalSketch sketch) {
        Preconditions.checkArgument(sketch.size() == nBuckets,
                "Sketch has invalid size. Expected %s, actual %s.", nBuckets, sketch.size());
        double rawEstimate = calculateRawEstimate(sketch);
        if (shouldPerformBiasCorrection(rawEstimate)) {
            rawEstimate -= biasEstimator.estimateBias(rawEstimate);
        }

        // Use linear counting if sketch contains buckets with 0 value.
        int nZeroBuckets = countZeroBuckets(sketch);
        if (nZeroBuckets > 0) {
            double linearCountingEstimate = calculateLinearCountingEstimate(nZeroBuckets);
            if (linearCountingEstimate <= linearCountingThreshold) {
                rawEstimate = linearCountingEstimate;
            }
        }

        return Math.round(rawEstimate);
    }
Estimates the number of unique elements.

@param sketch A sketch populated with values from the aggregation phase of HLL.
@return The estimated number of unique elements.
searchlib/src/main/java/com/yahoo/searchlib/aggregation/hll/HyperLogLogEstimator.java