| 2137 | // Always inline in IR so that constants can be replaced. |
| 2138 | template <typename T> |
| 2139 | IR_ALWAYS_INLINE void AggregateFunctions::HllUpdate( |
| 2140 | FunctionContext* ctx, const T& src, StringVal* dst, int precision) { |
| 2141 | if (src.is_null) return; |
| 2142 | DCHECK(!dst->is_null); |
| 2143 | |
| 2144 | const int& hll_len = dst->len; |
| 2145 | DCHECK_IN_RANGE(hll_len, MIN_HLL_LEN, MAX_HLL_LEN); |
| 2146 | |
| 2147 | uint64_t hash_value = |
| 2148 | AnyValUtil::Hash64(src, *ctx->GetArgType(0), HashUtil::FNV64_SEED); |
| 2149 | // Use the lower bits to index into the number of streams and then find the first 1 bit |
| 2150 | // after the index bits. |
| 2151 | int idx = hash_value & (hll_len - 1); |
| 2152 | const uint8_t first_one_bit = 1 |
| 2153 | + BitUtil::CountTrailingZeros( |
| 2154 | hash_value >> precision, sizeof(hash_value) * CHAR_BIT - precision); |
| 2155 | dst->ptr[idx] = ::max(dst->ptr[idx], first_one_bit); |
| 2156 | } |
| 2157 | |
| 2158 | // Update function for NDV() that accepts an expression only. |
| 2159 | template <typename T> |
nothing calls this directly
no test coverage detected