Skip to content

Commit 7b2d1c2

Browse files
committed
check if union gadget needs kxq rebuilding before getting estimates/bounds
1 parent 16bab2c commit 7b2d1c2

3 files changed

Lines changed: 47 additions & 2 deletions

File tree

hll/include/HllArray-internal.hpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,42 @@ bool HllArray<A>::isRebuildKxqCurminFlag() const {
594594
return rebuild_kxq_curmin_;
595595
}
596596

597+
template<typename A>
598+
void HllArray<A>::check_rebuild_kxq_cur_min() {
599+
if (!rebuild_kxq_curmin_) { return; }
600+
601+
uint8_t cur_min = 64;
602+
uint32_t num_at_cur_min = 0;
603+
double kxq0 = 1 << this->lgConfigK_;
604+
double kxq1 = 0;
605+
606+
auto it = this->begin(true); // want all points to adjust cur_min
607+
const auto end = this->end();
608+
while (it != end) {
609+
uint8_t v = HllUtil<A>::getValue(*it);
610+
if (v > 0) {
611+
if (v < 32) { kxq0 += INVERSE_POWERS_OF_2[v] - 1.0; }
612+
else { kxq1 += INVERSE_POWERS_OF_2[v] - 1.0; }
613+
}
614+
if (v > cur_min) { ++it; continue; }
615+
if (v < cur_min) {
616+
cur_min = v;
617+
num_at_cur_min = 1;
618+
} else {
619+
++num_at_cur_min;
620+
}
621+
++it;
622+
}
623+
624+
kxq0_ = kxq0;
625+
kxq1_ = kxq1;
626+
curMin_ = cur_min;
627+
numAtCurMin_ = num_at_cur_min;
628+
rebuild_kxq_curmin_ = false;
629+
// HipAccum is not affected
630+
631+
}
632+
597633
template<typename A>
598634
typename HllArray<A>::const_iterator HllArray<A>::begin(bool all) const {
599635
return const_iterator(hllByteArr_.data(), 1 << this->lgConfigK_, 0, this->tgtHllType_, nullptr, 0, all);

hll/include/HllArray.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ class HllArray : public HllSketchImpl<A> {
8787

8888
virtual AuxHashMap<A>* getAuxHashMap() const;
8989

90-
virtual void setRebuildKxqCurminFlag(bool rebuild);
91-
virtual bool isRebuildKxqCurminFlag() const;
90+
void setRebuildKxqCurminFlag(bool rebuild);
91+
bool isRebuildKxqCurminFlag() const;
92+
void check_rebuild_kxq_cur_min();
9293

9394
class const_iterator;
9495
virtual const_iterator begin(bool all = false) const;

hll/include/HllUnion-internal.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,21 +131,29 @@ void hll_union_alloc<A>::coupon_update(uint32_t coupon) {
131131

132132
template<typename A>
133133
double hll_union_alloc<A>::get_estimate() const {
134+
if (gadget_.sketch_impl->getCurMode() == hll_mode::HLL)
135+
static_cast<HllArray<A>*>(gadget_.sketch_impl)->check_rebuild_kxq_cur_min();
134136
return gadget_.get_estimate();
135137
}
136138

137139
template<typename A>
138140
double hll_union_alloc<A>::get_composite_estimate() const {
141+
if (gadget_.sketch_impl->getCurMode() == hll_mode::HLL)
142+
static_cast<HllArray<A>*>(gadget_.sketch_impl)->check_rebuild_kxq_cur_min();
139143
return gadget_.get_composite_estimate();
140144
}
141145

142146
template<typename A>
143147
double hll_union_alloc<A>::get_lower_bound(uint8_t num_std_dev) const {
148+
if (gadget_.sketch_impl->getCurMode() == hll_mode::HLL)
149+
static_cast<HllArray<A>*>(gadget_.sketch_impl)->check_rebuild_kxq_cur_min();
144150
return gadget_.get_lower_bound(num_std_dev);
145151
}
146152

147153
template<typename A>
148154
double hll_union_alloc<A>::get_upper_bound(uint8_t num_std_dev) const {
155+
if (gadget_.sketch_impl->getCurMode() == hll_mode::HLL)
156+
static_cast<HllArray<A>*>(gadget_.sketch_impl)->check_rebuild_kxq_cur_min();
149157
return gadget_.get_upper_bound(num_std_dev);
150158
}
151159

0 commit comments

Comments
 (0)