public long count() {
    // compute count only if the register values are updated else return the
    // cached count
    if (invalidateCount || cachedCount < 0) {
      if (encoding.equals(EncodingType.SPARSE)) {

        // if encoding is still SPARSE use linear counting with increase
        // accuracy (as we use pPrime bits for register index)
        int mPrime = 1 << sparseRegister.getPPrime();
        cachedCount = linearCount(mPrime, mPrime - sparseRegister.getSparseMap().size());
      } else {

        // for DENSE encoding, use bias table lookup for HLLNoBias algorithm
        // else fallback to HLLOriginal algorithm
        double sum = denseRegister.getSumInversePow2();
        long numZeros = denseRegister.getNumZeroes();

        // cardinality estimate from normalized bias corrected harmonic mean on
        // the registers
        cachedCount = (long) (alphaMM * (1.0 / sum));
        long pow = (long) Math.pow(2, chosenHashBits);

        // when bias correction is enabled
        if (noBias) {
          cachedCount = cachedCount <= 5 * m ? (cachedCount - estimateBias(cachedCount))
              : cachedCount;
          long h = cachedCount;
          if (numZeros != 0) {
            h = linearCount(m, numZeros);
          }

          if (h < getThreshold()) {
            cachedCount = h;
          }
        } else {
          // HLL algorithm shows stronger bias for values in (2.5 * m) range.
          // To compensate for this short range bias, linear counting is used
          // for values before this short range. The original paper also says
          // similar bias is seen for long range values due to hash collisions
          // in range >1/30*(2^32). For the default case, we do not have to
          // worry about this long range bias as the paper used 32-bit hashing
          // and we use 64-bit hashing as default. 2^64 values are too high to
          // observe long range bias (hash collisions).
          if (cachedCount <= 2.5 * m) {

            // for short range use linear counting
            if (numZeros != 0) {
              cachedCount = linearCount(m, numZeros);
            }
          } else if (chosenHashBits < 64 && cachedCount > (0.033333 * pow)) {

            // long range bias for 32-bit hashcodes
            if (cachedCount > (1 / 30) * pow) {
              cachedCount = (long) (-pow * Math.log(1.0 - (double) cachedCount / (double) pow));
            }
          }
        }
      }
      invalidateCount = false;
    }

    return cachedCount;
  }
Java's default charset will be used for strings.
@param val
         - input string
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/common/ndv/hll/HyperLogLog.java