HLL Data Types

HyperLoglog (HLL) is an approximation algorithm for efficiently counting the number of distinct values in a data set. It features faster computing and lower space usage. You only need to store HLL data structures, instead of data sets. When new data is added to a data set, make hash calculation on the data and insert the result to an HLL. Then, you can obtain the final result based on the HLL.

Table 1 compares HLL with other algorithms.

Table 1 Comparison between HLL and other algorithms

Item

Sorting Algorithm

Hash Algorithm

HLL

Time complexity

O(nlogn)

O(n)

O(n)

Space complexity

O(n)

O(n)

1280 bytes

Error rate

0

0

≈2%

Storage space requirement

Size of raw data

Size of raw data

1280 bytes

HLL has advantages over others in the computing speed and storage space requirement. In terms of time complexity, the sorting algorithm needs O(nlogn) time for sorting, and the hash algorithm and HLL need O(n) time for full table scanning. In terms of storage space requirements, the sorting algorithm and hash algorithm need to store raw data before collecting statistics, whereas the HLL algorithm needs to store only the HLL data structures rather than the raw data, and thereby occupying a fixed space of only 1280 bytes.

  • In default specifications, the maximum number of distinct values is 1.6e plus 12, and the maximum error rate is only 2.3%. If a calculation result exceeds the maximum number, the error rate of the calculation result will increase, or the calculation will fail and an error will be reported.
  • When using this feature for the first time, you need to evaluate the distinct values of the service, properly select configuration parameters, and perform verification to ensure that the accuracy meets requirements.
    • When default parameter configuration is used, the calculated number of distinct values is 1.6e plus 12. If the calculated result is NaN, you need to adjust log2m and regwidth to accommodate more distinct values.
    • The hash algorithm has an extremely low probability of collision. However, you are still advised to select 2 or 3 hash seeds for verification when using the hash algorithm for the first time. If there is only a small difference between the distinct values, you can select any one of the seeds as the hash seed.

Table 2 describes main HLL data structures.

Table 2 Main HLL data structures

Data Type

Description

hll

Its size is always 1280 bytes, which can be directly used to calculate the number of distinct values.

The following describes HLL application scenarios.