20 #ifndef _HLL6ARRAY_INTERNAL_HPP_
21 #define _HLL6ARRAY_INTERNAL_HPP_
25 #include "Hll6Array.hpp"
30 Hll6Array<A>::Hll6Array(uint8_t lgConfigK,
bool startFullSize,
const A& allocator):
33 const int numBytes = this->hll6ArrBytes(lgConfigK);
34 this->hllByteArr_.resize(numBytes, 0);
38 Hll6Array<A>::Hll6Array(
const HllArray<A>& other) :
39 HllArray<A>(other.getLgConfigK(),
target_hll_type::
HLL_6, other.isStartFullSize(), other.getAllocator())
41 const int numBytes = this->hll6ArrBytes(this->lgConfigK_);
42 this->hllByteArr_.resize(numBytes, 0);
43 this->oooFlag_ = other.isOutOfOrderFlag();
44 uint32_t num_zeros = 1 << this->lgConfigK_;
46 for (
const auto coupon : other) {
48 internalCouponUpdate(coupon);
51 this->numAtCurMin_ = num_zeros;
52 this->hipAccum_ = other.getHipAccum();
53 this->rebuild_kxq_curmin_ =
false;
57 std::function<void(HllSketchImpl<A>*)> Hll6Array<A>::get_deleter()
const {
58 return [](HllSketchImpl<A>* ptr) {
59 using Hll6Alloc =
typename std::allocator_traits<A>::template rebind_alloc<Hll6Array<A>>;
60 Hll6Array<A>* hll =
static_cast<Hll6Array<A>*
>(ptr);
61 Hll6Alloc hll6Alloc(hll->getAllocator());
63 hll6Alloc.deallocate(hll, 1);
68 Hll6Array<A>* Hll6Array<A>::copy()
const {
69 using Hll6Alloc =
typename std::allocator_traits<A>::template rebind_alloc<Hll6Array<A>>;
70 Hll6Alloc hll6Alloc(this->getAllocator());
71 return new (hll6Alloc.allocate(1)) Hll6Array<A>(*
this);
75 uint8_t Hll6Array<A>::getSlot(uint32_t slotNo)
const {
76 const uint32_t startBit = slotNo * 6;
77 const uint32_t shift = startBit & 0x7;
78 const uint32_t byteIdx = startBit >> 3;
79 const uint16_t twoByteVal = (this->hllByteArr_[byteIdx + 1] << 8) | this->hllByteArr_[byteIdx];
80 return (twoByteVal >> shift) & hll_constants::VAL_MASK_6;
84 void Hll6Array<A>::putSlot(uint32_t slotNo, uint8_t value) {
85 const uint32_t startBit = slotNo * 6;
86 const uint32_t shift = startBit & 0x7;
87 const uint32_t byteIdx = startBit >> 3;
88 const uint16_t valShifted = (value & 0x3F) << shift;
89 uint16_t curMasked = (this->hllByteArr_[byteIdx + 1] << 8) | this->hllByteArr_[byteIdx];
90 curMasked &= (~(hll_constants::VAL_MASK_6 << shift));
91 const uint16_t insert = curMasked | valShifted;
92 this->hllByteArr_[byteIdx] = insert & 0xFF;
93 this->hllByteArr_[byteIdx + 1] = (insert & 0xFF00) >> 8;
97 uint32_t Hll6Array<A>::getHllByteArrBytes()
const {
98 return this->hll6ArrBytes(this->lgConfigK_);
102 HllSketchImpl<A>* Hll6Array<A>::couponUpdate(uint32_t coupon) {
103 internalCouponUpdate(coupon);
108 void Hll6Array<A>::internalCouponUpdate(uint32_t coupon) {
109 const uint32_t configKmask = (1 << this->lgConfigK_) - 1;
110 const uint32_t slotNo = HllUtil<A>::getLow26(coupon) & configKmask;
111 const uint8_t newVal = HllUtil<A>::getValue(coupon);
113 const uint8_t curVal = getSlot(slotNo);
114 if (newVal > curVal) {
115 putSlot(slotNo, newVal);
116 this->hipAndKxQIncrementalUpdate(curVal, newVal);
118 this->numAtCurMin_--;
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