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

Function initHyperLogLog

src/backend/lib/hyperloglog.c:65–109  ·  view source on GitHub ↗

* Initialize HyperLogLog track state, by bit width * * bwidth is bit width (so register size will be 2 to the power of bwidth). * Must be between 4 and 16 inclusive. */

Source from the content-addressed store, hash-verified

63 * Must be between 4 and 16 inclusive.
64 */
65void
66initHyperLogLog(hyperLogLogState *cState, uint8 bwidth)
67{
68 double alpha;
69
70 if (bwidth < 4 || bwidth > 16)
71 elog(ERROR, "bit width must be between 4 and 16 inclusive");
72
73 cState->registerWidth = bwidth;
74 cState->nRegisters = (Size) 1 << bwidth;
75 cState->arrSize = sizeof(uint8) * cState->nRegisters + 1;
76
77 /*
78 * Initialize hashes array to zero, not negative infinity, per discussion
79 * of the coupon collector problem in the HyperLogLog paper
80 */
81 cState->hashesArr = palloc0(cState->arrSize);
82
83 /*
84 * "alpha" is a value that for each possible number of registers (m) is
85 * used to correct a systematic multiplicative bias present in m ^ 2 Z (Z
86 * is "the indicator function" through which we finally compute E,
87 * estimated cardinality).
88 */
89 switch (cState->nRegisters)
90 {
91 case 16:
92 alpha = 0.673;
93 break;
94 case 32:
95 alpha = 0.697;
96 break;
97 case 64:
98 alpha = 0.709;
99 break;
100 default:
101 alpha = 0.7213 / (1.0 + 1.079 / cState->nRegisters);
102 }
103
104 /*
105 * Precalculate alpha m ^ 2, later used to generate "raw" HyperLogLog
106 * estimate E
107 */
108 cState->alphaMM = alpha * cState->nRegisters * cState->nRegisters;
109}
110
111/*
112 * Initialize HyperLogLog track state, by error rate

Callers 7

network_sortsupportFunction · 0.85
macaddr_sortsupportFunction · 0.85
numeric_sortsupportFunction · 0.85
varstr_sortsupportFunction · 0.85
uuid_sortsupportFunction · 0.85
initHyperLogLogErrorFunction · 0.85
hashagg_spill_initFunction · 0.85

Calls 1

palloc0Function · 0.50

Tested by

no test coverage detected