MCPcopy Create free account
hub / github.com/apache/cloudberry / addHyperLogLog

Function addHyperLogLog

src/backend/lib/hyperloglog.c:166–180  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

164 * observed.
165 */
166void
167addHyperLogLog(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

Callers 6

network_abbrev_convertFunction · 0.85
macaddr_abbrev_convertFunction · 0.85
varstr_abbrev_convertFunction · 0.85
uuid_abbrev_convertFunction · 0.85
hashagg_spill_tupleFunction · 0.85

Calls 1

rhoFunction · 0.85

Tested by

no test coverage detected