@Override public long cardinality(){
switch (format) {
case NORMAL:
    double registerSum=0;
  int count=registerSet.count;
double zeros=0;
for (int j=0; j < registerSet.count; j++) {
int val=registerSet.get(j);
registerSum+=1.0 / (1 << val);
if (val == 0) {
  zeros++;
}
}
double estimate=alphaMM * (1 / registerSum);
double estimatePrime=estimate;
if (estimate <= (5 * m)) {
estimatePrime=estimate - getEstimateBias(estimate,p);
}
double H;
if (zeros > 0) {
H=HyperLogLog.linearCounting(count,zeros);
}
 else {
H=estimatePrime;
}
if ((p <= 18 && H < thresholdData[p - 4]) || (p > 18 && estimate <= 5 * m)) {
return Math.round(H);
}
 else {
return Math.round(estimatePrime);
}
case SPARSE:
mergeTempList();
return Math.round(HyperLogLog.linearCounting(sm,(sm - sparseSet.length)));
}
return 0;
}

@ Override public long cardinality ( ) { switch ( format ) { case NORMAL : double registerSum = 0 ; int count = registerSet . count ; double zeros = 0 ; for ( int j = 0 ; j < registerSet . count ; j ++ ) { int val = registerSet . get ( j ) ; registerSum += 1.0 / ( 1 << val ) ; if ( val == 0 ) { zeros ++ ; } } double estimate = alphaMM * ( 1 / registerSum ) ; double estimatePrime = estimate ; if ( estimate <= ( 5 * m ) ) { estimatePrime = estimate - getEstimateBias ( estimate , p ) ; } double H ; if ( zeros > 0 ) { H = HyperLogLog . linearCounting ( count , zeros ) ; } else { H = estimatePrime ; } if ( ( p <= 18 && H < thresholdData [ p - 4 ] ) || ( p > 18 && estimate <= 5 * m ) ) { return Math . round ( H ) ; } else { return Math . round ( estimatePrime ) ; } case SPARSE : mergeTempList ( ) ; return Math . round ( HyperLogLog . linearCounting ( sm , ( sm - sparseSet . length ) ) ) ; } return 0 ; }
gather the cardinality estimate from this estimator . < p / > has two procedures based on current mode . ' normal ' mode works similar to hll but has some new bias corrections . ' sparse ' mode is linear counting .
