private static void bitpackHLLRegister(OutputStream out, byte[] register, int bitWidth)
      throws IOException {
    int bitsLeft = 8;
    byte current = 0;

    if (bitWidth == 8) {
      fastPathWrite(out, register);
      return;
    }

    // write the blob
    for (byte value : register) {
      int bitsToWrite = bitWidth;
      while (bitsToWrite > bitsLeft) {
        // add the bits to the bottom of the current word
        current |= value >>> (bitsToWrite - bitsLeft);
        // subtract out the bits we just added
        bitsToWrite -= bitsLeft;
        // zero out the bits above bitsToWrite
        value &= (1 << bitsToWrite) - 1;
        out.write(current);
        current = 0;
        bitsLeft = 8;
      }
      bitsLeft -= bitsToWrite;
      current |= value << bitsLeft;
      if (bitsLeft == 0) {
        out.write(current);
        current = 0;
        bitsLeft = 8;
      }
    }

    out.flush();
  }
This function deserializes the serialized hyperloglogs from a byte array.
@param buf - to deserialize
@return HyperLogLog
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/common/ndv/hll/HyperLogLogUtils.java