* Adds element to the estimator, from caller-supplied hash. * * It is critical that the hash value passed be an actual hash value, typically * generated using hash_any(). The algorithm relies on a specific bit-pattern * observable in conjunction with stochastic averaging. There must be a * uniform distribution of bits in hash values for each distinct original value * observed. */
| 164 | * observed. |
| 165 | */ |
| 166 | void |
| 167 | addHyperLogLog(hyperLogLogState *cState, uint32 hash) |
| 168 | { |
| 169 | uint8 count; |
| 170 | uint32 index; |
| 171 | |
| 172 | /* Use the first "k" (registerWidth) bits as a zero based index */ |
| 173 | index = hash >> (BITS_PER_BYTE * sizeof(uint32) - cState->registerWidth); |
| 174 | |
| 175 | /* Compute the rank of the remaining 32 - "k" (registerWidth) bits */ |
| 176 | count = rho(hash << cState->registerWidth, |
| 177 | BITS_PER_BYTE * sizeof(uint32) - cState->registerWidth); |
| 178 | |
| 179 | cState->hashesArr[index] = Max(count, cState->hashesArr[index]); |
| 180 | } |
| 181 | |
| 182 | /* |
| 183 | * Estimates cardinality, based on elements added so far |
no test coverage detected