public long cardinality() {
    double sum = 0;
    int zeros = 0;

    // Compute the harmonic mean of 2^register[i]
    for (int i = 0; i < m; i++) {
      sum += 1.0 / (1 << registers[i]);
      if (registers[i] == 0) {
        zeros++;
      }
    }

    // Apply bias correction formula
    double estimate = alpha * m * m / sum;

    // Small range correction
    if (estimate <= 2.5 * m) {
      if (zeros > 0) {
        // Linear counting for small cardinalities
        return Math.round(m * Math.log((double) m / zeros));
      }
    }

    // Large range correction (for values > 2^32 / 30)
    double maxCardinality = (double) (1L << 32);
    if (estimate > maxCardinality / 30) {
      return Math.round(-maxCardinality * Math.log(1 - estimate / maxCardinality));
    }

    return Math.round(estimate);
  }
Returns the estimated cardinality of the data set.

@return The estimated cardinality
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/aggregation/approximate/HyperLogLog.java