| 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 | |
| 14 | namespace duckdb_hll { |
| 15 | |
| 16 | /* Error codes */ |
| 17 | #define HLL_C_OK 0 |
| 18 | #define HLL_C_ERR -1 |
| 19 | |
| 20 | struct robj { |
| 21 | void *ptr; |
| 22 | }; |
| 23 | |
| 24 | //! Create a new empty HyperLogLog object |
| 25 | robj *hll_create(void); |
| 26 | //! Convert hll from sparse to dense |
| 27 | int hllSparseToDense(robj *o); |
| 28 | //! Destroy the specified HyperLogLog object |
| 29 | void 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. |
| 32 | int 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. |
| 35 | int 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. |
| 37 | robj *hll_merge(robj **hlls, size_t hll_count); |
| 38 | //! Get size (in bytes) of the HLL |
| 39 | uint64_t get_size(); |
| 40 | |
| 41 | uint64_t MurmurHash64A(const void *key, int len, unsigned int seed); |
| 42 | |
| 43 | } // namespace duckdb_hll |
| 44 | |
| 45 | namespace duckdb { |
| 46 | |
| 47 | void AddToLogsInternal(UnifiedVectorFormat &vdata, idx_t count, uint64_t indices[], uint8_t counts[], void ***logs[], |
| 48 | const SelectionVector *log_sel); |
| 49 | |
| 50 | void AddToSingleLogInternal(UnifiedVectorFormat &vdata, idx_t count, uint64_t indices[], uint8_t counts[], void *log); |
| 51 | |
| 52 | } // namespace duckdb |
| 53 | |