20 #ifndef _HLL8ARRAY_INTERNAL_HPP_
21 #define _HLL8ARRAY_INTERNAL_HPP_
23 #include "Hll8Array.hpp"
28 Hll8Array<A>::Hll8Array(uint8_t lgConfigK,
bool startFullSize,
const A& allocator):
31 const int numBytes = this->hll8ArrBytes(lgConfigK);
32 this->hllByteArr_.resize(numBytes, 0);
36 Hll8Array<A>::Hll8Array(
const HllArray<A>& other):
37 HllArray<A>(other.getLgConfigK(),
target_hll_type::
HLL_8, other.isStartFullSize(), other.getAllocator())
39 const int numBytes = this->hll8ArrBytes(this->lgConfigK_);
40 this->hllByteArr_.resize(numBytes, 0);
41 this->oooFlag_ = other.isOutOfOrderFlag();
42 uint32_t num_zeros = 1 << this->lgConfigK_;
44 for (
const auto coupon : other) {
46 internalCouponUpdate(coupon);
49 this->numAtCurMin_ = num_zeros;
50 this->hipAccum_ = other.getHipAccum();
51 this->rebuild_kxq_curmin_ =
false;
55 std::function<void(HllSketchImpl<A>*)> Hll8Array<A>::get_deleter()
const {
56 return [](HllSketchImpl<A>* ptr) {
57 Hll8Array<A>* hll =
static_cast<Hll8Array<A>*
>(ptr);
58 using Hll8Alloc =
typename std::allocator_traits<A>::template rebind_alloc<Hll8Array<A>>;
59 Hll8Alloc hll8Alloc(hll->getAllocator());
61 hll8Alloc.deallocate(hll, 1);
66 Hll8Array<A>* Hll8Array<A>::copy()
const {
67 using Hll8Alloc =
typename std::allocator_traits<A>::template rebind_alloc<Hll8Array<A>>;
68 Hll8Alloc hll8Alloc(this->getAllocator());
69 return new (hll8Alloc.allocate(1)) Hll8Array<A>(*
this);
73 uint8_t Hll8Array<A>::getSlot(uint32_t slotNo)
const {
74 return this->hllByteArr_[slotNo];
78 void Hll8Array<A>::putSlot(uint32_t slotNo, uint8_t value) {
79 this->hllByteArr_[slotNo] = value;
83 uint32_t Hll8Array<A>::getHllByteArrBytes()
const {
84 return this->hll8ArrBytes(this->lgConfigK_);
88 HllSketchImpl<A>* Hll8Array<A>::couponUpdate(uint32_t coupon) {
89 internalCouponUpdate(coupon);
94 void Hll8Array<A>::internalCouponUpdate(uint32_t coupon) {
95 const uint32_t configKmask = (1 << this->lgConfigK_) - 1;
96 const uint32_t slotNo = HllUtil<A>::getLow26(coupon) & configKmask;
97 const uint8_t newVal = HllUtil<A>::getValue(coupon);
99 const uint8_t curVal = this->hllByteArr_[slotNo];
100 if (newVal > curVal) {
101 this->hllByteArr_[slotNo] = newVal;
102 this->hipAndKxQIncrementalUpdate(curVal, newVal);
103 this->numAtCurMin_ -= curVal == 0;
108 void Hll8Array<A>::mergeList(
const CouponList<A>& src) {
109 for (
const auto coupon: src) {
110 internalCouponUpdate(coupon);
115 void Hll8Array<A>::mergeHll(
const HllArray<A>& src) {
118 if (this->getLgConfigK() == src.getLgConfigK()) {
119 if (src.getTgtHllType() == target_hll_type::HLL_8) {
121 for (
const auto value: src.getHllArray()) {
122 this->hllByteArr_[i] = std::max(this->hllByteArr_[i], value);
125 }
else if (src.getTgtHllType() == target_hll_type::HLL_6) {
126 const uint32_t src_k = 1 << src.getLgConfigK();
128 const uint8_t* ptr = src.getHllArray().data();
130 uint8_t value = *ptr & 0x3f;
131 this->hllByteArr_[i] = std::max(this->hllByteArr_[i], value);
134 value |= (*ptr & 0x0f) << 2;
135 this->hllByteArr_[i] = std::max(this->hllByteArr_[i], value);
138 value |= (*ptr & 3) << 4;
139 this->hllByteArr_[i] = std::max(this->hllByteArr_[i], value);
142 this->hllByteArr_[i] = std::max(this->hllByteArr_[i], value);
146 const auto& src4 =
static_cast<const Hll4Array<A>&
>(src);
148 for (
const auto byte: src.getHllArray()) {
149 this->hllByteArr_[i] = std::max(this->hllByteArr_[i], src4.adjustRawValue(i,
byte & hll_constants::loNibbleMask));
151 this->hllByteArr_[i] = std::max(this->hllByteArr_[i], src4.adjustRawValue(i,
byte >> 4));
157 const uint32_t dst_mask = (1 << this->getLgConfigK()) - 1;
159 if (src.getTgtHllType() == target_hll_type::HLL_8) {
161 for (
const auto value: src.getHllArray()) {
162 processValue(i++, dst_mask, value);
164 }
else if (src.getTgtHllType() == target_hll_type::HLL_6) {
165 const uint32_t src_k = 1 << src.getLgConfigK();
167 const uint8_t* ptr = src.getHllArray().data();
169 uint8_t value = *ptr & 0x3f;
170 processValue(i++, dst_mask, value);
172 value |= (*ptr & 0x0f) << 2;
173 processValue(i++, dst_mask, value);
175 value |= (*ptr & 3) << 4;
176 processValue(i++, dst_mask, value);
178 processValue(i++, dst_mask, value);
181 const auto& src4 =
static_cast<const Hll4Array<A>&
>(src);
183 for (
const auto byte: src.getHllArray()) {
184 processValue(i, dst_mask, src4.adjustRawValue(i,
byte & hll_constants::loNibbleMask));
186 processValue(i, dst_mask, src4.adjustRawValue(i,
byte >> 4));
191 this->setRebuildKxqCurminFlag(
true);
196 void Hll8Array<A>::processValue(uint32_t slot, uint32_t mask, uint8_t new_val) {
197 const size_t index = slot & mask;
198 this->hllByteArr_[index] = std::max(this->hllByteArr_[index], new_val);
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_8
8 bits per entry (fastest, fixed size)
Definition: hll.hpp:75