23#include "common_defs.hpp"
34template<
typename A>
class hll_sketch_alloc;
38using hll_sketch = hll_sketch_alloc<std::allocator<uint8_t>>;
112template<
typename A>
class HllSketchImpl;
114template<
typename A = std::allocator<u
int8_t> >
115class hll_sketch_alloc final {
129 explicit hll_sketch_alloc(uint8_t lg_config_k,
target_hll_type tgt_type =
HLL_4,
bool start_full_size =
false,
const A& allocator = A());
135 hll_sketch_alloc(
const hll_sketch_alloc<A>& that);
142 hll_sketch_alloc(
const hll_sketch_alloc<A>& that,
target_hll_type tgt_type);
148 hll_sketch_alloc(hll_sketch_alloc<A>&& that)
noexcept;
155 static hll_sketch_alloc deserialize(std::istream& is,
const A& allocator = A());
163 static hll_sketch_alloc deserialize(
const void* bytes,
size_t len,
const A& allocator = A());
173 hll_sketch_alloc& operator=(
const hll_sketch_alloc<A>& other);
180 hll_sketch_alloc& operator=(hll_sketch_alloc<A>&& other);
190 void reset(
bool full_size =
false);
194 using vector_bytes = std::vector<uint8_t, typename std::allocator_traits<A>::template rebind_alloc<uint8_t>>;
202 vector_bytes serialize_compact(
unsigned header_size_bytes = 0)
const;
209 vector_bytes serialize_updatable()
const;
216 void serialize_compact(std::ostream& os)
const;
223 void serialize_updatable(std::ostream& os)
const;
233 string<A> to_string(
bool summary =
true,
235 bool aux_detail =
false,
236 bool all =
false)
const;
244 void update(
const std::string& datum);
250 void update(uint64_t datum);
256 void update(uint32_t datum);
262 void update(uint16_t datum);
268 void update(uint8_t datum);
274 void update(int64_t datum);
280 void update(int32_t datum);
286 void update(int16_t datum);
292 void update(int8_t datum);
298 void update(
double datum);
304 void update(
float datum);
311 void update(
const void* data,
size_t length_bytes);
317 double get_estimate()
const;
330 double get_composite_estimate()
const;
338 double get_lower_bound(uint8_t num_std_dev)
const;
346 double get_upper_bound(uint8_t num_std_dev)
const;
352 uint8_t get_lg_config_k()
const;
364 bool is_compact()
const;
370 bool is_empty()
const;
376 uint32_t get_compact_serialization_bytes()
const;
382 uint32_t get_updatable_serialization_bytes()
const;
395 static uint32_t get_max_updatable_serialization_bytes(uint8_t lg_k,
target_hll_type tgt_type);
407 static double get_rel_err(
bool upper_bound,
bool unioned,
408 uint8_t lg_config_k, uint8_t num_std_dev);
411 explicit hll_sketch_alloc(HllSketchImpl<A>* that);
413 void coupon_update(uint32_t coupon);
415 std::string type_as_string()
const;
416 std::string mode_as_string()
const;
418 hll_mode get_current_mode()
const;
419 uint8_t get_serialization_version()
const;
420 bool is_out_of_order_flag()
const;
421 bool is_estimation_mode()
const;
423 HllSketchImpl<A>* sketch_impl;
424 friend hll_union_alloc<A>;
452template<
typename A = std::allocator<u
int8_t> >
534 void update(
const hll_sketch_alloc<A>& sketch);
540 void update(hll_sketch_alloc<A>&& sketch);
615 void update(
const void* data,
size_t length_bytes);
628 uint8_t lg_config_k, uint8_t num_std_dev);
641 inline void union_impl(
const hll_sketch_alloc<A>& sketch, uint8_t lg_max_k);
645 void coupon_update(uint32_t coupon);
647 hll_mode get_current_mode()
const;
648 bool is_out_of_order_flag()
const;
649 bool is_estimation_mode()
const;
655 hll_sketch_alloc<A> gadget_;
660#include "hll.private.hpp"
This is a high performance implementation of Phillipe Flajolet's HLL sketch but with significantly im...
Definition HllSketchImpl.hpp:31
This performs union operations for HLL sketches.
Definition hll.hpp:453
target_hll_type get_target_type() const
Returns the union's target HLL mode (from target_hll_type).
Definition HllUnion-internal.hpp:200
double get_composite_estimate() const
This is less accurate than the get_estimate() method and is automatically used when the union has gon...
Definition HllUnion-internal.hpp:144
void update(uint16_t datum)
Present the given unsigned 16-bit integer as a potential unique item.
Definition HllUnion-internal.hpp:81
double get_estimate() const
Returns the current cardinality estimate.
Definition HllUnion-internal.hpp:136
void update(const hll_sketch_alloc< A > &sketch)
Update this union operator with the given sketch.
Definition HllUnion-internal.hpp:49
void update(const std::string &datum)
Present the given std::string as a potential unique item.
Definition HllUnion-internal.hpp:66
void update(int8_t datum)
Present the given signed 8-bit integer as a potential unique item.
Definition HllUnion-internal.hpp:106
hll_sketch_alloc< A > get_result(target_hll_type tgt_type=HLL_4) const
Returns the result of this union operator with the specified target_hll_type.
Definition HllUnion-internal.hpp:41
bool is_empty() const
Indicates if the union is currently empty.
Definition HllUnion-internal.hpp:180
void update(float datum)
Present the given 32-bit floating point value as a potential unique item.
Definition HllUnion-internal.hpp:116
void update(hll_sketch_alloc< A > &&sketch)
Update this union operator with the given temporary sketch.
Definition HllUnion-internal.hpp:55
void update(uint32_t datum)
Present the given unsigned 32-bit integer as a potential unique item.
Definition HllUnion-internal.hpp:76
void update(int16_t datum)
Present the given signed 16-bit integer as a potential unique item.
Definition HllUnion-internal.hpp:101
void update(int32_t datum)
Present the given signed 32-bit integer as a potential unique item.
Definition HllUnion-internal.hpp:96
uint8_t get_lg_config_k() const
Returns union's configured lg_k value.
Definition HllUnion-internal.hpp:168
double get_lower_bound(uint8_t num_std_dev) const
Returns the approximate lower error bound given the specified number of standard deviations.
Definition HllUnion-internal.hpp:152
void update(const void *data, size_t length_bytes)
Present the given data array as a potential unique item.
Definition HllUnion-internal.hpp:121
hll_union_alloc(uint8_t lg_max_k, const A &allocator=A())
Construct an hll_union operator with the given maximum log2 of k.
Definition HllUnion-internal.hpp:35
void reset()
Resets the union to an empty state in coupon collection mode.
Definition HllUnion-internal.hpp:173
void update(double datum)
Present the given 64-bit floating point value as a potential unique item.
Definition HllUnion-internal.hpp:111
void update(int64_t datum)
Present the given signed 64-bit integer as a potential unique item.
Definition HllUnion-internal.hpp:91
void update(uint8_t datum)
Present the given unsigned 8-bit integer as a potential unique item.
Definition HllUnion-internal.hpp:86
void update(uint64_t datum)
Present the given unsigned 64-bit integer as a potential unique item.
Definition HllUnion-internal.hpp:71
static double get_rel_err(bool upper_bound, bool unioned, uint8_t lg_config_k, uint8_t num_std_dev)
Gets the current (approximate) Relative Error (RE) asymptotic values given several parameters.
Definition HllUnion-internal.hpp:205
double get_upper_bound(uint8_t num_std_dev) const
Returns the approximate upper error bound given the specified number of standard deviations.
Definition HllUnion-internal.hpp:160
DataSketches namespace.
Definition binomial_bounds.hpp:38
target_hll_type
Specifies the target type of HLL sketch to be created.
Definition hll.hpp:72
@ HLL_6
6 bits per entry (fixed size)
Definition hll.hpp:74
@ HLL_8
8 bits per entry (fastest, fixed size)
Definition hll.hpp:75
@ HLL_4
4 bits per entry (most compact, size may vary)
Definition hll.hpp:73
hll_union_alloc< std::allocator< uint8_t > > hll_union
HLL union alias with default allocator.
Definition hll.hpp:40
hll_sketch_alloc< std::allocator< uint8_t > > hll_sketch
HLL sketch alias with default allocator.
Definition hll.hpp:38