1//===----------------------------------------------------------------------===//
2// DuckDB
3//
4// third_party/hyperloglog/hyperloglog.hpp
5//
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include <stdint.h>
12#include <string.h>
13
14namespace duckdb_hll {
15
16/* Error codes */
17#define HLL_C_OK 0
18#define HLL_C_ERR -1
19
20struct robj {
21 void *ptr;
22};
23
24//! Create a new empty HyperLogLog object
25robj *hll_create(void);
26//! Convert hll from sparse to dense
27int hllSparseToDense(robj *o);
28//! Destroy the specified HyperLogLog object
29void hll_destroy(robj *obj);
30//! Add an element with the specified amount of bytes to the HyperLogLog. Returns C_ERR on failure, otherwise returns 0
31//! if the cardinality did not change, and 1 otherwise.
32int hll_add(robj *o, unsigned char *ele, size_t elesize);
33//! Returns the estimated amount of unique elements seen by the HyperLogLog. Returns C_OK on success, or C_ERR on
34//! failure.
35int hll_count(robj *o, size_t *result);
36//! Merge hll_count HyperLogLog objects into a single one. Returns NULL on failure, or the new HLL object on success.
37robj *hll_merge(robj **hlls, size_t hll_count);
38//! Get size (in bytes) of the HLL
39uint64_t get_size();
40
41uint64_t MurmurHash64A(const void *key, int len, unsigned int seed);
42
43} // namespace duckdb_hll
44
45namespace duckdb {
46
47void AddToLogsInternal(UnifiedVectorFormat &vdata, idx_t count, uint64_t indices[], uint8_t counts[], void ***logs[],
48 const SelectionVector *log_sel);
49
50void AddToSingleLogInternal(UnifiedVectorFormat &vdata, idx_t count, uint64_t indices[], uint8_t counts[], void *log);
51
52} // namespace duckdb
53