20#ifndef _HLL8ARRAY_INTERNAL_HPP_
21#define _HLL8ARRAY_INTERNAL_HPP_
23#include "Hll8Array.hpp"
28Hll8Array<A>::Hll8Array(uint8_t lgConfigK,
const A& allocator):
31 const int numBytes = this->hll8ArrBytes(lgConfigK);
32 this->hllByteArr_.resize(numBytes, 0);
36Hll8Array<A>::Hll8Array(
const HllArray<A>& other):
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;
55std::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);
66Hll8Array<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);
73uint8_t Hll8Array<A>::getSlot(uint32_t slotNo)
const {
74 return this->hllByteArr_[slotNo];
78void Hll8Array<A>::putSlot(uint32_t slotNo, uint8_t value) {
79 this->hllByteArr_[slotNo] = value;
83uint32_t Hll8Array<A>::getHllByteArrBytes()
const {
84 return this->hll8ArrBytes(this->lgConfigK_);
88HllSketchImpl<A>* Hll8Array<A>::couponUpdate(uint32_t coupon) {
89 internalCouponUpdate(coupon);
94void 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) {
103 this->check_rebuild_kxq_cur_min();
104 this->hllByteArr_[slotNo] = newVal;
105 this->hipAndKxQIncrementalUpdate(curVal, newVal);
106 this->numAtCurMin_ -= curVal == 0;
111void Hll8Array<A>::mergeList(
const CouponList<A>& src) {
112 for (
const auto coupon: src) {
113 internalCouponUpdate(coupon);
118void Hll8Array<A>::mergeHll(
const HllArray<A>& src) {
121 if (this->getLgConfigK() == src.getLgConfigK()) {
122 if (src.getTgtHllType() == target_hll_type::HLL_8) {
124 for (
const auto value: src.getHllArray()) {
125 this->hllByteArr_[i] = std::max(this->hllByteArr_[i], value);
128 }
else if (src.getTgtHllType() == target_hll_type::HLL_6) {
129 const uint32_t src_k = 1 << src.getLgConfigK();
131 const uint8_t* ptr = src.getHllArray().data();
133 uint8_t value = *ptr & 0x3f;
134 this->hllByteArr_[i] = std::max(this->hllByteArr_[i], value);
137 value |= (*ptr & 0x0f) << 2;
138 this->hllByteArr_[i] = std::max(this->hllByteArr_[i], value);
141 value |= (*ptr & 3) << 4;
142 this->hllByteArr_[i] = std::max(this->hllByteArr_[i], value);
145 this->hllByteArr_[i] = std::max(this->hllByteArr_[i], value);
149 const auto& src4 =
static_cast<const Hll4Array<A>&
>(src);
151 for (
const auto byte: src.getHllArray()) {
152 this->hllByteArr_[i] = std::max(this->hllByteArr_[i], src4.adjustRawValue(i,
byte & hll_constants::loNibbleMask));
154 this->hllByteArr_[i] = std::max(this->hllByteArr_[i], src4.adjustRawValue(i,
byte >> 4));
160 const uint32_t dst_mask = (1 << this->getLgConfigK()) - 1;
162 if (src.getTgtHllType() == target_hll_type::HLL_8) {
164 for (
const auto value: src.getHllArray()) {
165 processValue(i++, dst_mask, value);
167 }
else if (src.getTgtHllType() == target_hll_type::HLL_6) {
168 const uint32_t src_k = 1 << src.getLgConfigK();
170 const uint8_t* ptr = src.getHllArray().data();
172 uint8_t value = *ptr & 0x3f;
173 processValue(i++, dst_mask, value);
175 value |= (*ptr & 0x0f) << 2;
176 processValue(i++, dst_mask, value);
178 value |= (*ptr & 3) << 4;
179 processValue(i++, dst_mask, value);
181 processValue(i++, dst_mask, value);
184 const auto& src4 =
static_cast<const Hll4Array<A>&
>(src);
186 for (
const auto byte: src.getHllArray()) {
187 processValue(i, dst_mask, src4.adjustRawValue(i,
byte & hll_constants::loNibbleMask));
189 processValue(i, dst_mask, src4.adjustRawValue(i,
byte >> 4));
194 this->setRebuildKxqCurminFlag(
true);
199void Hll8Array<A>::processValue(uint32_t slot, uint32_t mask, uint8_t new_val) {
200 const size_t index = slot & mask;
201 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