Compute the register histogram in the sparse representation. */
| 909 | |
| 910 | /* Compute the register histogram in the sparse representation. */ |
| 911 | void hllSparseRegHisto(uint8_t *sparse, int sparselen, int *invalid, int* reghisto) { |
| 912 | int idx = 0, runlen, regval; |
| 913 | uint8_t *end = sparse+sparselen, *p = sparse; |
| 914 | |
| 915 | while(p < end) { |
| 916 | if (HLL_SPARSE_IS_ZERO(p)) { |
| 917 | runlen = HLL_SPARSE_ZERO_LEN(p); |
| 918 | idx += runlen; |
| 919 | reghisto[0] += runlen; |
| 920 | p++; |
| 921 | } else if (HLL_SPARSE_IS_XZERO(p)) { |
| 922 | runlen = HLL_SPARSE_XZERO_LEN(p); |
| 923 | idx += runlen; |
| 924 | reghisto[0] += runlen; |
| 925 | p += 2; |
| 926 | } else { |
| 927 | runlen = HLL_SPARSE_VAL_LEN(p); |
| 928 | regval = HLL_SPARSE_VAL_VALUE(p); |
| 929 | idx += runlen; |
| 930 | reghisto[regval] += runlen; |
| 931 | p++; |
| 932 | } |
| 933 | } |
| 934 | if (idx != HLL_REGISTERS && invalid) *invalid = 1; |
| 935 | } |
| 936 | |
| 937 | /* ========================= HyperLogLog Count ============================== |
| 938 | * This is the core of the algorithm where the approximated count is computed. |