20 #ifndef _HLLARRAY_HPP_
21 #define _HLLARRAY_HPP_
23 #include "HllSketchImpl.hpp"
24 #include "HllUtil.hpp"
32 class HllArray :
public HllSketchImpl<A> {
34 using vector_bytes = std::vector<uint8_t, typename std::allocator_traits<A>::template rebind_alloc<uint8_t>>;
36 HllArray(uint8_t lgConfigK,
target_hll_type tgtHllType,
bool startFullSize,
const A& allocator);
39 static HllArray* newHll(
const void* bytes,
size_t len,
const A& allocator);
40 static HllArray* newHll(std::istream& is,
const A& allocator);
42 virtual vector_bytes serialize(
bool compact,
unsigned header_size_bytes)
const;
43 virtual void serialize(std::ostream& os,
bool compact)
const;
45 virtual ~HllArray() =
default;
46 virtual std::function<void(HllSketchImpl<A>*)> get_deleter()
const = 0;
48 virtual HllArray* copy()
const = 0;
51 virtual HllSketchImpl<A>* couponUpdate(uint32_t coupon) = 0;
53 virtual double getEstimate()
const;
54 virtual double getCompositeEstimate()
const;
55 virtual double getLowerBound(uint8_t numStdDev)
const;
56 virtual double getUpperBound(uint8_t numStdDev)
const;
58 inline uint8_t getCurMin()
const;
59 inline uint32_t getNumAtCurMin()
const;
60 inline double getHipAccum()
const;
62 virtual uint32_t getHllByteArrBytes()
const = 0;
64 virtual uint32_t getUpdatableSerializationBytes()
const;
65 virtual uint32_t getCompactSerializationBytes()
const;
67 virtual bool isOutOfOrderFlag()
const;
68 virtual bool isEmpty()
const;
69 virtual bool isCompact()
const;
71 virtual void putOutOfOrderFlag(
bool flag);
73 inline double getKxQ0()
const;
74 inline double getKxQ1()
const;
76 virtual uint32_t getMemDataStart()
const;
77 virtual uint8_t getPreInts()
const;
79 void putCurMin(uint8_t curMin);
80 void putHipAccum(
double hipAccum);
81 inline void putKxQ0(
double kxq0);
82 inline void putKxQ1(
double kxq1);
83 void putNumAtCurMin(uint32_t numAtCurMin);
85 static uint32_t hllArrBytes(
target_hll_type tgtHllType, uint8_t lgConfigK);
86 static uint32_t hll4ArrBytes(uint8_t lgConfigK);
87 static uint32_t hll6ArrBytes(uint8_t lgConfigK);
88 static uint32_t hll8ArrBytes(uint8_t lgConfigK);
90 virtual AuxHashMap<A>* getAuxHashMap()
const;
92 void setRebuildKxqCurminFlag(
bool rebuild);
93 bool isRebuildKxqCurminFlag()
const;
94 void check_rebuild_kxq_cur_min();
97 virtual const_iterator begin(
bool all =
false)
const;
98 virtual const_iterator end()
const;
100 virtual A getAllocator()
const;
102 const vector_bytes& getHllArray()
const;
105 void hipAndKxQIncrementalUpdate(uint8_t oldValue, uint8_t newValue);
106 double getHllBitMapEstimate()
const;
107 double getHllRawEstimate()
const;
112 vector_bytes hllByteArr_;
114 uint32_t numAtCurMin_;
116 bool rebuild_kxq_curmin_;
118 friend class HllSketchImplFactory<A>;
122 class HllArray<A>::const_iterator {
124 using iterator_category = std::input_iterator_tag;
125 using value_type = uint32_t;
126 using difference_type = void;
127 using pointer = uint32_t*;
128 using reference = uint32_t;
130 const_iterator(
const uint8_t* array, uint32_t array_slze, uint32_t index,
target_hll_type hll_type,
const AuxHashMap<A>* exceptions, uint8_t offset,
bool all);
131 const_iterator& operator++();
132 bool operator!=(
const const_iterator& other)
const;
133 reference operator*()
const;
135 const uint8_t* array_;
136 uint32_t array_size_;
139 const AuxHashMap<A>* exceptions_;
143 static inline uint8_t get_value(
const uint8_t* array, uint32_t index,
target_hll_type hll_type,
const AuxHashMap<A>* exceptions, uint8_t offset);
DataSketches namespace.
Definition: binomial_bounds.hpp:38
target_hll_type
Specifies the target type of HLL sketch to be created.
Definition: hll.hpp:72