23 #include "common_defs.hpp"
24 #include "HllUtil.hpp"
34 template<
typename A>
class hll_sketch_alloc;
35 template<
typename A>
class hll_union_alloc;
38 using hll_sketch = hll_sketch_alloc<std::allocator<uint8_t>>;
112 template<
typename A>
class HllSketchImpl;
114 template<
typename A = std::allocator<u
int8_t> >
115 class hll_sketch_alloc final {
126 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());
132 hll_sketch_alloc(
const hll_sketch_alloc<A>& that);
139 hll_sketch_alloc(
const hll_sketch_alloc<A>& that,
target_hll_type tgt_type);
145 hll_sketch_alloc(hll_sketch_alloc<A>&& that) noexcept;
152 static hll_sketch_alloc deserialize(std::istream& is,
const A& allocator = A());
160 static hll_sketch_alloc deserialize(
const void* bytes,
size_t len,
const A& allocator = A());
163 virtual ~hll_sketch_alloc();
170 hll_sketch_alloc& operator=(
const hll_sketch_alloc<A>& other);
177 hll_sketch_alloc& operator=(hll_sketch_alloc<A>&& other);
187 using vector_bytes = std::vector<uint8_t, typename std::allocator_traits<A>::template rebind_alloc<uint8_t>>;
195 vector_bytes serialize_compact(
unsigned header_size_bytes = 0)
const;
202 vector_bytes serialize_updatable()
const;
209 void serialize_compact(std::ostream& os)
const;
216 void serialize_updatable(std::ostream& os)
const;
226 string<A> to_string(
bool summary =
true,
228 bool aux_detail =
false,
229 bool all =
false)
const;
237 void update(
const std::string& datum);
243 void update(uint64_t datum);
249 void update(uint32_t datum);
255 void update(uint16_t datum);
261 void update(uint8_t datum);
267 void update(int64_t datum);
273 void update(int32_t datum);
279 void update(int16_t datum);
285 void update(int8_t datum);
291 void update(
double datum);
297 void update(
float datum);
304 void update(
const void* data,
size_t length_bytes);
310 double get_estimate()
const;
323 double get_composite_estimate()
const;
331 double get_lower_bound(uint8_t num_std_dev)
const;
339 double get_upper_bound(uint8_t num_std_dev)
const;
345 uint8_t get_lg_config_k()
const;
357 bool is_compact()
const;
363 bool is_empty()
const;
369 uint32_t get_compact_serialization_bytes()
const;
375 uint32_t get_updatable_serialization_bytes()
const;
388 static uint32_t get_max_updatable_serialization_bytes(uint8_t lg_k,
target_hll_type tgt_type);
400 static double get_rel_err(
bool upper_bound,
bool unioned,
401 uint8_t lg_config_k, uint8_t num_std_dev);
404 explicit hll_sketch_alloc(HllSketchImpl<A>* that);
406 void coupon_update(uint32_t coupon);
408 std::string type_as_string()
const;
409 std::string mode_as_string()
const;
411 hll_mode get_current_mode()
const;
412 uint8_t get_serialization_version()
const;
413 bool is_out_of_order_flag()
const;
414 bool is_estimation_mode()
const;
416 HllSketchImpl<A>* sketch_impl;
417 friend hll_union_alloc<A>;
445 template<
typename A = std::allocator<u
int8_t> >
527 void update(
const hll_sketch_alloc<A>& sketch);
533 void update(hll_sketch_alloc<A>&& sketch);
541 void update(
const std::string& datum);
547 void update(uint64_t datum);
553 void update(uint32_t datum);
559 void update(uint16_t datum);
565 void update(uint8_t datum);
571 void update(int64_t datum);
577 void update(int32_t datum);
583 void update(int16_t datum);
589 void update(int8_t datum);
595 void update(
double datum);
608 void update(
const void* data,
size_t length_bytes);
620 static double get_rel_err(
bool upper_bound,
bool unioned,
621 uint8_t lg_config_k, uint8_t num_std_dev);
634 inline void union_impl(
const hll_sketch_alloc<A>& sketch, uint8_t lg_max_k);
638 void coupon_update(uint32_t coupon);
640 hll_mode get_current_mode()
const;
641 bool is_out_of_order_flag()
const;
642 bool is_estimation_mode()
const;
648 hll_sketch_alloc<A> gadget_;
653 #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:446
target_hll_type get_target_type() const
Returns the union's target HLL mode (from target_hll_type).
Definition: HllUnion-internal.hpp:191
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:140
double get_estimate() const
Returns the current cardinality estimate.
Definition: HllUnion-internal.hpp:133
void update(const hll_sketch_alloc< A > &sketch)
Update this union operator with the given sketch.
Definition: HllUnion-internal.hpp:46
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:171
uint8_t get_lg_config_k() const
Returns union's configured lg_k value.
Definition: HllUnion-internal.hpp:161
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:147
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:166
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:196
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:154
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_sketch_alloc< std::allocator< uint8_t > > hll_sketch
HLL sketch alias with default allocator.
Definition: hll.hpp:38