23#include "common_defs.hpp"
34template<
typename A>
class hll_sketch_alloc;
38using hll_sketch = hll_sketch_alloc<std::allocator<uint8_t>>;
115template<
typename A>
class HllSketchImpl;
117template<
typename A = std::allocator<u
int8_t> >
118class hll_sketch_alloc final {
132 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());
138 hll_sketch_alloc(
const hll_sketch_alloc<A>& that);
145 hll_sketch_alloc(
const hll_sketch_alloc<A>& that,
target_hll_type tgt_type);
151 hll_sketch_alloc(hll_sketch_alloc<A>&& that)
noexcept;
158 static hll_sketch_alloc deserialize(std::istream& is,
const A& allocator = A());
166 static hll_sketch_alloc deserialize(
const void* bytes,
size_t len,
const A& allocator = A());
176 hll_sketch_alloc& operator=(
const hll_sketch_alloc<A>& other);
183 hll_sketch_alloc& operator=(hll_sketch_alloc<A>&& other);
193 void reset(
bool full_size =
false);
197 using vector_bytes = std::vector<uint8_t, typename std::allocator_traits<A>::template rebind_alloc<uint8_t>>;
205 vector_bytes serialize_compact(
unsigned header_size_bytes = 0)
const;
212 vector_bytes serialize_updatable()
const;
219 void serialize_compact(std::ostream& os)
const;
226 void serialize_updatable(std::ostream& os)
const;
236 string<A> to_string(
bool summary =
true,
238 bool aux_detail =
false,
239 bool all =
false)
const;
247 void update(
const std::string& datum);
253 void update(uint64_t datum);
259 void update(uint32_t datum);
265 void update(uint16_t datum);
271 void update(uint8_t datum);
277 void update(int64_t datum);
283 void update(int32_t datum);
289 void update(int16_t datum);
295 void update(int8_t datum);
301 void update(
double datum);
307 void update(
float datum);
314 void update(
const void* data,
size_t length_bytes);
320 double get_estimate()
const;
333 double get_composite_estimate()
const;
341 double get_lower_bound(uint8_t num_std_dev)
const;
349 double get_upper_bound(uint8_t num_std_dev)
const;
355 uint8_t get_lg_config_k()
const;
367 bool is_compact()
const;
373 bool is_empty()
const;
379 uint32_t get_compact_serialization_bytes()
const;
385 uint32_t get_updatable_serialization_bytes()
const;
398 static uint32_t get_max_updatable_serialization_bytes(uint8_t lg_k,
target_hll_type tgt_type);
410 static double get_rel_err(
bool upper_bound,
bool unioned,
411 uint8_t lg_config_k, uint8_t num_std_dev);
414 explicit hll_sketch_alloc(HllSketchImpl<A>* that);
416 void coupon_update(uint32_t coupon);
418 std::string type_as_string()
const;
419 std::string mode_as_string()
const;
421 hll_mode get_current_mode()
const;
422 uint8_t get_serialization_version()
const;
423 bool is_out_of_order_flag()
const;
424 bool is_estimation_mode()
const;
426 HllSketchImpl<A>* sketch_impl;
427 friend hll_union_alloc<A>;
461template<
typename A = std::allocator<u
int8_t> >
569 void update(
const hll_sketch_alloc<A>& sketch);
575 void update(hll_sketch_alloc<A>&& sketch);
650 void update(
const void* data,
size_t length_bytes);
663 uint8_t lg_config_k, uint8_t num_std_dev);
676 inline void union_impl(
const hll_sketch_alloc<A>& sketch, uint8_t lg_max_k);
680 void coupon_update(uint32_t coupon);
682 hll_mode get_current_mode()
const;
683 bool is_out_of_order_flag()
const;
684 bool is_estimation_mode()
const;
687 hll_sketch_alloc<A> gadget_;
692#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:462
target_hll_type get_target_type() const
Returns the union's target HLL mode (from target_hll_type).
Definition HllUnion-internal.hpp:210
hll_union_alloc(hll_union_alloc &&that)=default
Move constructor.
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:154
hll_union_alloc(const hll_union_alloc &that)=default
Copy constructor.
void update(uint16_t datum)
Present the given unsigned 16-bit integer as a potential unique item.
Definition HllUnion-internal.hpp:91
double get_estimate() const
Returns the current cardinality estimate.
Definition HllUnion-internal.hpp:146
void update(const hll_sketch_alloc< A > &sketch)
Update this union operator with the given sketch.
Definition HllUnion-internal.hpp:57
void update(const std::string &datum)
Present the given std::string as a potential unique item.
Definition HllUnion-internal.hpp:76
void update(int8_t datum)
Present the given signed 8-bit integer as a potential unique item.
Definition HllUnion-internal.hpp:116
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:49
bool is_empty() const
Indicates if the union is currently empty.
Definition HllUnion-internal.hpp:190
void update(float datum)
Present the given 32-bit floating point value as a potential unique item.
Definition HllUnion-internal.hpp:126
void update(hll_sketch_alloc< A > &&sketch)
Update this union operator with the given temporary sketch.
Definition HllUnion-internal.hpp:63
void update(uint32_t datum)
Present the given unsigned 32-bit integer as a potential unique item.
Definition HllUnion-internal.hpp:86
void update(int16_t datum)
Present the given signed 16-bit integer as a potential unique item.
Definition HllUnion-internal.hpp:111
void update(int32_t datum)
Present the given signed 32-bit integer as a potential unique item.
Definition HllUnion-internal.hpp:106
uint8_t get_lg_config_k() const
Returns union's configured lg_k value.
Definition HllUnion-internal.hpp:178
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:162
void update(const void *data, size_t length_bytes)
Present the given data array as a potential unique item.
Definition HllUnion-internal.hpp:131
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
hll_union_alloc & operator=(hll_union_alloc &&other)=default
Move assignment operator.
hll_union_alloc & operator=(const hll_union_alloc &other)
Copy assignment operator.
void reset()
Resets the union to an empty state in coupon collection mode.
Definition HllUnion-internal.hpp:183
void update(double datum)
Present the given 64-bit floating point value as a potential unique item.
Definition HllUnion-internal.hpp:121
void update(int64_t datum)
Present the given signed 64-bit integer as a potential unique item.
Definition HllUnion-internal.hpp:101
void update(uint8_t datum)
Present the given unsigned 8-bit integer as a potential unique item.
Definition HllUnion-internal.hpp:96
void update(uint64_t datum)
Present the given unsigned 64-bit integer as a potential unique item.
Definition HllUnion-internal.hpp:81
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:215
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:170
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