namespace hll_constants
diff --git a/hll/include/AuxHashMap-internal.hpp b/hll/include/AuxHashMap-internal.hpp
index f409793..751c74a 100644
--- a/hll/include/AuxHashMap-internal.hpp
+++ b/hll/include/AuxHashMap-internal.hpp
@@ -78,7 +78,7 @@
auxHashMap = new (ahmAlloc(allocator).allocate(1)) AuxHashMap<A>(lgArrInts, lgConfigK, allocator);
for (uint32_t i = 0; i < itemsToRead; ++i) {
const uint32_t pair = auxPtr[i];
- if (pair == HllUtil<A>::EMPTY) { continue; }
+ if (pair == hll_constants::EMPTY) { continue; }
const uint32_t slotNo = HllUtil<A>::getLow26(pair) & configKmask;
const uint8_t value = HllUtil<A>::getValue(pair);
auxHashMap->mustAdd(slotNo, value);
@@ -121,7 +121,7 @@
const uint32_t itemsToRead = 1 << lgAuxArrInts;
for (uint32_t i = 0; i < itemsToRead; ++i) {
const auto pair = read<int>(is);
- if (pair == HllUtil<A>::EMPTY) { continue; }
+ if (pair == hll_constants::EMPTY) { continue; }
const uint32_t slotNo = HllUtil<A>::getLow26(pair) & configKmask;
const uint8_t value = HllUtil<A>::getValue(pair);
auxHashMap->mustAdd(slotNo, value);
@@ -214,7 +214,7 @@
template<typename A>
void AuxHashMap<A>::checkGrow() {
- if ((HllUtil<A>::RESIZE_DENOM * auxCount) > (HllUtil<A>::RESIZE_NUMER * (1 << lgAuxArrInts))) {
+ if ((hll_constants::RESIZE_DENOM * auxCount) > (hll_constants::RESIZE_NUMER * (1 << lgAuxArrInts))) {
growAuxSpace();
}
}
@@ -226,7 +226,7 @@
vector_int entries_new(newArrLen, 0, entries.get_allocator());
for (size_t i = 0; i < entries.size(); ++i) {
const uint32_t fetched = entries[i];
- if (fetched != HllUtil<A>::EMPTY) {
+ if (fetched != hll_constants::EMPTY) {
// find empty in new array
const int32_t idx = find(entries_new.data(), lgAuxArrInts, lgConfigK, fetched & configKmask);
entries_new[~idx] = fetched;
@@ -248,7 +248,7 @@
const uint32_t loopIndex = probe;
do {
const uint32_t arrVal = auxArr[probe];
- if (arrVal == HllUtil<A>::EMPTY) { //Compares on entire entry
+ if (arrVal == hll_constants::EMPTY) { //Compares on entire entry
return ~probe; //empty
}
else if (slotNo == (arrVal & configKmask)) { //Compares only on slotNo
diff --git a/hll/include/CompositeInterpolationXTable-internal.hpp b/hll/include/CompositeInterpolationXTable-internal.hpp
index 347ea5c..0f6cae6 100644
--- a/hll/include/CompositeInterpolationXTable-internal.hpp
+++ b/hll/include/CompositeInterpolationXTable-internal.hpp
@@ -37,12 +37,12 @@
template<typename A>
uint32_t CompositeInterpolationXTable<A>::get_y_stride(uint8_t logK) {
- if (logK < HllUtil<A>::MIN_LOG_K || logK > HllUtil<A>::MAX_LOG_K) {
- throw std::invalid_argument("logK must be in range [" + std::to_string(HllUtil<A>::MIN_LOG_K)
- + ", " + std::to_string(HllUtil<A>::MAX_LOG_K) + "]. Found: "
+ if (logK < hll_constants::MIN_LOG_K || logK > hll_constants::MAX_LOG_K) {
+ throw std::invalid_argument("logK must be in range [" + std::to_string(hll_constants::MIN_LOG_K)
+ + ", " + std::to_string(hll_constants::MAX_LOG_K) + "]. Found: "
+ std::to_string(logK));
}
- return yStrides[logK - HllUtil<A>::MIN_LOG_K];
+ return yStrides[logK - hll_constants::MIN_LOG_K];
}
template<typename A>
@@ -798,14 +798,14 @@
template<typename A>
const double* CompositeInterpolationXTable<A>::get_x_arr(uint8_t logK) {
- if (logK < HllUtil<A>::MIN_LOG_K || logK > HllUtil<A>::MAX_LOG_K) {
- throw std::invalid_argument("logK must be in range [" + std::to_string(HllUtil<A>::MIN_LOG_K)
- + ", " + std::to_string(HllUtil<A>::MAX_LOG_K) + "]. Found: "
+ if (logK < hll_constants::MIN_LOG_K || logK > hll_constants::MAX_LOG_K) {
+ throw std::invalid_argument("logK must be in range [" + std::to_string(hll_constants::MIN_LOG_K)
+ + ", " + std::to_string(hll_constants::MAX_LOG_K) + "]. Found: "
+ std::to_string(logK));
}
- return xArray[logK - HllUtil<A>::MIN_LOG_K];
+ return xArray[logK - hll_constants::MIN_LOG_K];
}
}
-#endif // _COMPOSITEINTERPOLATIONXTABLE_INTERNAL_HPP_
\ No newline at end of file
+#endif // _COMPOSITEINTERPOLATIONXTABLE_INTERNAL_HPP_
diff --git a/hll/include/CouponHashSet-internal.hpp b/hll/include/CouponHashSet-internal.hpp
index 5db9772..e7b5768 100644
--- a/hll/include/CouponHashSet-internal.hpp
+++ b/hll/include/CouponHashSet-internal.hpp
@@ -56,45 +56,45 @@
template<typename A>
CouponHashSet<A>* CouponHashSet<A>::newSet(const void* bytes, size_t len, const A& allocator) {
- if (len < HllUtil<A>::HASH_SET_INT_ARR_START) { // hard-coded
+ if (len < hll_constants::HASH_SET_INT_ARR_START) { // hard-coded
throw std::out_of_range("Input data length insufficient to hold CouponHashSet");
}
const uint8_t* data = static_cast<const uint8_t*>(bytes);
- if (data[HllUtil<A>::PREAMBLE_INTS_BYTE] != HllUtil<A>::HASH_SET_PREINTS) {
+ if (data[hll_constants::PREAMBLE_INTS_BYTE] != hll_constants::HASH_SET_PREINTS) {
throw std::invalid_argument("Incorrect number of preInts in input stream");
}
- if (data[HllUtil<A>::SER_VER_BYTE] != HllUtil<A>::SER_VER) {
+ if (data[hll_constants::SER_VER_BYTE] != hll_constants::SER_VER) {
throw std::invalid_argument("Wrong ser ver in input stream");
}
- if (data[HllUtil<A>::FAMILY_BYTE] != HllUtil<A>::FAMILY_ID) {
+ if (data[hll_constants::FAMILY_BYTE] != hll_constants::FAMILY_ID) {
throw std::invalid_argument("Input stream is not an HLL sketch");
}
- const hll_mode mode = HllSketchImpl<A>::extractCurMode(data[HllUtil<A>::MODE_BYTE]);
+ const hll_mode mode = HllSketchImpl<A>::extractCurMode(data[hll_constants::MODE_BYTE]);
if (mode != SET) {
throw std::invalid_argument("Calling set constructor with non-set mode data");
}
- const target_hll_type tgtHllType = HllSketchImpl<A>::extractTgtHllType(data[HllUtil<A>::MODE_BYTE]);
+ const target_hll_type tgtHllType = HllSketchImpl<A>::extractTgtHllType(data[hll_constants::MODE_BYTE]);
- const uint8_t lgK = data[HllUtil<A>::LG_K_BYTE];
+ const uint8_t lgK = data[hll_constants::LG_K_BYTE];
if (lgK <= 7) {
throw std::invalid_argument("Attempt to deserialize invalid CouponHashSet with lgConfigK <= 7. Found: "
+ std::to_string(lgK));
}
- uint8_t lgArrInts = data[HllUtil<A>::LG_ARR_BYTE];
- const bool compactFlag = ((data[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::COMPACT_FLAG_MASK) ? true : false);
+ uint8_t lgArrInts = data[hll_constants::LG_ARR_BYTE];
+ const bool compactFlag = ((data[hll_constants::FLAGS_BYTE] & hll_constants::COMPACT_FLAG_MASK) ? true : false);
uint32_t couponCount;
- std::memcpy(&couponCount, data + HllUtil<A>::HASH_SET_COUNT_INT, sizeof(couponCount));
- if (lgArrInts < HllUtil<A>::LG_INIT_SET_SIZE) {
- lgArrInts = HllUtil<A>::computeLgArrInts(SET, couponCount, lgK);
+ std::memcpy(&couponCount, data + hll_constants::HASH_SET_COUNT_INT, sizeof(couponCount));
+ if (lgArrInts < hll_constants::LG_INIT_SET_SIZE) {
+ lgArrInts = HllUtil<>::computeLgArrInts(SET, couponCount, lgK);
}
// Don't set couponCount in sketch here;
// we'll set later if updatable, and increment with updates if compact
const uint32_t couponsInArray = (compactFlag ? couponCount : (1 << lgArrInts));
- const size_t expectedLength = HllUtil<A>::HASH_SET_INT_ARR_START + (couponsInArray * sizeof(uint32_t));
+ const size_t expectedLength = hll_constants::HASH_SET_INT_ARR_START + (couponsInArray * sizeof(uint32_t));
if (len < expectedLength) {
throw std::out_of_range("Byte array too short for sketch. Expected " + std::to_string(expectedLength)
+ ", found: " + std::to_string(len));
@@ -104,7 +104,7 @@
CouponHashSet<A>* sketch = new (chsa.allocate(1)) CouponHashSet<A>(lgK, tgtHllType, allocator);
if (compactFlag) {
- const uint8_t* curPos = data + HllUtil<A>::HASH_SET_INT_ARR_START;
+ const uint8_t* curPos = data + hll_constants::HASH_SET_INT_ARR_START;
uint32_t coupon;
for (uint32_t i = 0; i < couponCount; ++i, curPos += sizeof(coupon)) {
std::memcpy(&coupon, curPos, sizeof(coupon));
@@ -115,7 +115,7 @@
sketch->couponCount_ = couponCount;
// only need to read valid coupons, unlike in stream case
std::memcpy(sketch->coupons_.data(),
- data + HllUtil<A>::HASH_SET_INT_ARR_START,
+ data + hll_constants::HASH_SET_INT_ARR_START,
couponCount * sizeof(uint32_t));
}
@@ -127,34 +127,34 @@
uint8_t listHeader[8];
read(is, listHeader, 8 * sizeof(uint8_t));
- if (listHeader[HllUtil<A>::PREAMBLE_INTS_BYTE] != HllUtil<A>::HASH_SET_PREINTS) {
+ if (listHeader[hll_constants::PREAMBLE_INTS_BYTE] != hll_constants::HASH_SET_PREINTS) {
throw std::invalid_argument("Incorrect number of preInts in input stream");
}
- if (listHeader[HllUtil<A>::SER_VER_BYTE] != HllUtil<A>::SER_VER) {
+ if (listHeader[hll_constants::SER_VER_BYTE] != hll_constants::SER_VER) {
throw std::invalid_argument("Wrong ser ver in input stream");
}
- if (listHeader[HllUtil<A>::FAMILY_BYTE] != HllUtil<A>::FAMILY_ID) {
+ if (listHeader[hll_constants::FAMILY_BYTE] != hll_constants::FAMILY_ID) {
throw std::invalid_argument("Input stream is not an HLL sketch");
}
- hll_mode mode = HllSketchImpl<A>::extractCurMode(listHeader[HllUtil<A>::MODE_BYTE]);
+ hll_mode mode = HllSketchImpl<A>::extractCurMode(listHeader[hll_constants::MODE_BYTE]);
if (mode != SET) {
throw std::invalid_argument("Calling set constructor with non-set mode data");
}
- const target_hll_type tgtHllType = HllSketchImpl<A>::extractTgtHllType(listHeader[HllUtil<A>::MODE_BYTE]);
+ const target_hll_type tgtHllType = HllSketchImpl<A>::extractTgtHllType(listHeader[hll_constants::MODE_BYTE]);
- const uint8_t lgK = listHeader[HllUtil<A>::LG_K_BYTE];
+ const uint8_t lgK = listHeader[hll_constants::LG_K_BYTE];
if (lgK <= 7) {
throw std::invalid_argument("Attempt to deserialize invalid CouponHashSet with lgConfigK <= 7. Found: "
+ std::to_string(lgK));
}
- uint8_t lgArrInts = listHeader[HllUtil<A>::LG_ARR_BYTE];
- const bool compactFlag = ((listHeader[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::COMPACT_FLAG_MASK) ? true : false);
+ uint8_t lgArrInts = listHeader[hll_constants::LG_ARR_BYTE];
+ const bool compactFlag = ((listHeader[hll_constants::FLAGS_BYTE] & hll_constants::COMPACT_FLAG_MASK) ? true : false);
const auto couponCount = read<uint32_t>(is);
- if (lgArrInts < HllUtil<A>::LG_INIT_SET_SIZE) {
- lgArrInts = HllUtil<A>::computeLgArrInts(SET, couponCount, lgK);
+ if (lgArrInts < hll_constants::LG_INIT_SET_SIZE) {
+ lgArrInts = HllUtil<>::computeLgArrInts(SET, couponCount, lgK);
}
ChsAlloc chsa(allocator);
@@ -211,17 +211,17 @@
template<typename A>
uint32_t CouponHashSet<A>::getMemDataStart() const {
- return HllUtil<A>::HASH_SET_INT_ARR_START;
+ return hll_constants::HASH_SET_INT_ARR_START;
}
template<typename A>
uint8_t CouponHashSet<A>::getPreInts() const {
- return HllUtil<A>::HASH_SET_PREINTS;
+ return hll_constants::HASH_SET_PREINTS;
}
template<typename A>
bool CouponHashSet<A>::checkGrowOrPromote() {
- if (static_cast<size_t>(HllUtil<A>::RESIZE_DENOM * this->couponCount_) > (HllUtil<A>::RESIZE_NUMER * this->coupons_.size())) {
+ if (static_cast<size_t>(hll_constants::RESIZE_DENOM * this->couponCount_) > (hll_constants::RESIZE_NUMER * this->coupons_.size())) {
const uint8_t lgCouponArrInts = count_trailing_zeros_in_u32(static_cast<uint32_t>(this->coupons_.size()));
if (lgCouponArrInts == (this->lgConfigK_ - 3)) { // at max size
return true; // promote to HLL
@@ -239,7 +239,7 @@
const uint32_t srcLen = static_cast<uint32_t>(this->coupons_.size());
for (uint32_t i = 0; i < srcLen; ++i) { // scan existing array for non-zero values
const uint32_t fetched = this->coupons_[i];
- if (fetched != HllUtil<A>::EMPTY) {
+ if (fetched != hll_constants::EMPTY) {
const int32_t idx = find<A>(coupons_new.data(), tgtLgCoupArrSize, fetched); // search TGT array
if (idx < 0) { // found EMPTY
coupons_new[~idx] = fetched; // insert
@@ -258,13 +258,13 @@
const uint32_t loopIndex = probe;
do {
const uint32_t couponAtIdx = array[probe];
- if (couponAtIdx == HllUtil<A>::EMPTY) {
+ if (couponAtIdx == hll_constants::EMPTY) {
return ~probe; //empty
}
else if (coupon == couponAtIdx) {
return probe; //duplicate
}
- const uint32_t stride = ((coupon & HllUtil<A>::KEY_MASK_26) >> lgArrInts) | 1;
+ const uint32_t stride = ((coupon & hll_constants::KEY_MASK_26) >> lgArrInts) | 1;
probe = (probe + stride) & arrMask;
} while (probe != loopIndex);
throw std::invalid_argument("Key not found and no empty slots!");
diff --git a/hll/include/CouponList-internal.hpp b/hll/include/CouponList-internal.hpp
index 3bc5ea4..c80c294 100644
--- a/hll/include/CouponList-internal.hpp
+++ b/hll/include/CouponList-internal.hpp
@@ -35,7 +35,7 @@
HllSketchImpl<A>(lgConfigK, tgtHllType, mode, false),
couponCount_(0),
oooFlag_(false),
-coupons_(1ULL << (mode == hll_mode::LIST ? HllUtil<A>::LG_INIT_LIST_SIZE : HllUtil<A>::LG_INIT_SET_SIZE), 0, allocator)
+coupons_(1ULL << (mode == hll_mode::LIST ? hll_constants::LG_INIT_LIST_SIZE : hll_constants::LG_INIT_SET_SIZE), 0, allocator)
{}
template<typename A>
@@ -70,36 +70,36 @@
template<typename A>
CouponList<A>* CouponList<A>::newList(const void* bytes, size_t len, const A& allocator) {
- if (len < HllUtil<A>::LIST_INT_ARR_START) {
+ if (len < hll_constants::LIST_INT_ARR_START) {
throw std::out_of_range("Input data length insufficient to hold CouponHashSet");
}
const uint8_t* data = static_cast<const uint8_t*>(bytes);
- if (data[HllUtil<A>::PREAMBLE_INTS_BYTE] != HllUtil<A>::LIST_PREINTS) {
+ if (data[hll_constants::PREAMBLE_INTS_BYTE] != hll_constants::LIST_PREINTS) {
throw std::invalid_argument("Incorrect number of preInts in input stream");
}
- if (data[HllUtil<A>::SER_VER_BYTE] != HllUtil<A>::SER_VER) {
+ if (data[hll_constants::SER_VER_BYTE] != hll_constants::SER_VER) {
throw std::invalid_argument("Wrong ser ver in input stream");
}
- if (data[HllUtil<A>::FAMILY_BYTE] != HllUtil<A>::FAMILY_ID) {
+ if (data[hll_constants::FAMILY_BYTE] != hll_constants::FAMILY_ID) {
throw std::invalid_argument("Input stream is not an HLL sketch");
}
- hll_mode mode = HllSketchImpl<A>::extractCurMode(data[HllUtil<A>::MODE_BYTE]);
+ hll_mode mode = HllSketchImpl<A>::extractCurMode(data[hll_constants::MODE_BYTE]);
if (mode != LIST) {
throw std::invalid_argument("Calling list constructor with non-list mode data");
}
- target_hll_type tgtHllType = HllSketchImpl<A>::extractTgtHllType(data[HllUtil<A>::MODE_BYTE]);
+ target_hll_type tgtHllType = HllSketchImpl<A>::extractTgtHllType(data[hll_constants::MODE_BYTE]);
- const uint8_t lgK = data[HllUtil<A>::LG_K_BYTE];
- const bool compact = ((data[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::COMPACT_FLAG_MASK) ? true : false);
- const bool oooFlag = ((data[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::OUT_OF_ORDER_FLAG_MASK) ? true : false);
- const bool emptyFlag = ((data[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::EMPTY_FLAG_MASK) ? true : false);
+ const uint8_t lgK = data[hll_constants::LG_K_BYTE];
+ const bool compact = ((data[hll_constants::FLAGS_BYTE] & hll_constants::COMPACT_FLAG_MASK) ? true : false);
+ const bool oooFlag = ((data[hll_constants::FLAGS_BYTE] & hll_constants::OUT_OF_ORDER_FLAG_MASK) ? true : false);
+ const bool emptyFlag = ((data[hll_constants::FLAGS_BYTE] & hll_constants::EMPTY_FLAG_MASK) ? true : false);
- const uint32_t couponCount = data[HllUtil<A>::LIST_COUNT_BYTE];
+ const uint32_t couponCount = data[hll_constants::LIST_COUNT_BYTE];
const uint32_t couponsInArray = (compact ? couponCount : (1 << HllUtil<A>::computeLgArrInts(LIST, couponCount, lgK)));
- const size_t expectedLength = HllUtil<A>::LIST_INT_ARR_START + (couponsInArray * sizeof(uint32_t));
+ const size_t expectedLength = hll_constants::LIST_INT_ARR_START + (couponsInArray * sizeof(uint32_t));
if (len < expectedLength) {
throw std::out_of_range("Byte array too short for sketch. Expected " + std::to_string(expectedLength)
+ ", found: " + std::to_string(len));
@@ -112,7 +112,7 @@
if (!emptyFlag) {
// only need to read valid coupons, unlike in stream case
- std::memcpy(sketch->coupons_.data(), data + HllUtil<A>::LIST_INT_ARR_START, couponCount * sizeof(uint32_t));
+ std::memcpy(sketch->coupons_.data(), data + hll_constants::LIST_INT_ARR_START, couponCount * sizeof(uint32_t));
}
return sketch;
@@ -123,33 +123,33 @@
uint8_t listHeader[8];
read(is, listHeader, 8 * sizeof(uint8_t));
- if (listHeader[HllUtil<A>::PREAMBLE_INTS_BYTE] != HllUtil<A>::LIST_PREINTS) {
+ if (listHeader[hll_constants::PREAMBLE_INTS_BYTE] != hll_constants::LIST_PREINTS) {
throw std::invalid_argument("Incorrect number of preInts in input stream");
}
- if (listHeader[HllUtil<A>::SER_VER_BYTE] != HllUtil<A>::SER_VER) {
+ if (listHeader[hll_constants::SER_VER_BYTE] != hll_constants::SER_VER) {
throw std::invalid_argument("Wrong ser ver in input stream");
}
- if (listHeader[HllUtil<A>::FAMILY_BYTE] != HllUtil<A>::FAMILY_ID) {
+ if (listHeader[hll_constants::FAMILY_BYTE] != hll_constants::FAMILY_ID) {
throw std::invalid_argument("Input stream is not an HLL sketch");
}
- hll_mode mode = HllSketchImpl<A>::extractCurMode(listHeader[HllUtil<A>::MODE_BYTE]);
+ hll_mode mode = HllSketchImpl<A>::extractCurMode(listHeader[hll_constants::MODE_BYTE]);
if (mode != LIST) {
throw std::invalid_argument("Calling list constructor with non-list mode data");
}
- const target_hll_type tgtHllType = HllSketchImpl<A>::extractTgtHllType(listHeader[HllUtil<A>::MODE_BYTE]);
+ const target_hll_type tgtHllType = HllSketchImpl<A>::extractTgtHllType(listHeader[hll_constants::MODE_BYTE]);
- const uint8_t lgK = listHeader[HllUtil<A>::LG_K_BYTE];
- const bool compact = ((listHeader[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::COMPACT_FLAG_MASK) ? true : false);
- const bool oooFlag = ((listHeader[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::OUT_OF_ORDER_FLAG_MASK) ? true : false);
- const bool emptyFlag = ((listHeader[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::EMPTY_FLAG_MASK) ? true : false);
+ const uint8_t lgK = listHeader[hll_constants::LG_K_BYTE];
+ const bool compact = ((listHeader[hll_constants::FLAGS_BYTE] & hll_constants::COMPACT_FLAG_MASK) ? true : false);
+ const bool oooFlag = ((listHeader[hll_constants::FLAGS_BYTE] & hll_constants::OUT_OF_ORDER_FLAG_MASK) ? true : false);
+ const bool emptyFlag = ((listHeader[hll_constants::FLAGS_BYTE] & hll_constants::EMPTY_FLAG_MASK) ? true : false);
ClAlloc cla(allocator);
CouponList<A>* sketch = new (cla.allocate(1)) CouponList<A>(lgK, tgtHllType, mode, allocator);
using coupon_list_ptr = std::unique_ptr<CouponList<A>, std::function<void(HllSketchImpl<A>*)>>;
coupon_list_ptr ptr(sketch, sketch->get_deleter());
- const uint32_t couponCount = listHeader[HllUtil<A>::LIST_COUNT_BYTE];
+ const uint32_t couponCount = listHeader[hll_constants::LIST_COUNT_BYTE];
sketch->couponCount_ = couponCount;
sketch->putOutOfOrderFlag(oooFlag); // should always be false for LIST
@@ -173,17 +173,17 @@
vector_u8<A> byteArr(sketchSizeBytes, 0, getAllocator());
uint8_t* bytes = byteArr.data() + header_size_bytes;
- bytes[HllUtil<A>::PREAMBLE_INTS_BYTE] = static_cast<uint8_t>(getPreInts());
- bytes[HllUtil<A>::SER_VER_BYTE] = static_cast<uint8_t>(HllUtil<A>::SER_VER);
- bytes[HllUtil<A>::FAMILY_BYTE] = static_cast<uint8_t>(HllUtil<A>::FAMILY_ID);
- bytes[HllUtil<A>::LG_K_BYTE] = static_cast<uint8_t>(this->lgConfigK_);
- bytes[HllUtil<A>::LG_ARR_BYTE] = count_trailing_zeros_in_u32(static_cast<uint32_t>(coupons_.size()));
- bytes[HllUtil<A>::FLAGS_BYTE] = this->makeFlagsByte(compact);
- bytes[HllUtil<A>::LIST_COUNT_BYTE] = static_cast<uint8_t>(this->mode_ == LIST ? couponCount_ : 0);
- bytes[HllUtil<A>::MODE_BYTE] = this->makeModeByte();
+ bytes[hll_constants::PREAMBLE_INTS_BYTE] = static_cast<uint8_t>(getPreInts());
+ bytes[hll_constants::SER_VER_BYTE] = static_cast<uint8_t>(hll_constants::SER_VER);
+ bytes[hll_constants::FAMILY_BYTE] = static_cast<uint8_t>(hll_constants::FAMILY_ID);
+ bytes[hll_constants::LG_K_BYTE] = static_cast<uint8_t>(this->lgConfigK_);
+ bytes[hll_constants::LG_ARR_BYTE] = count_trailing_zeros_in_u32(static_cast<uint32_t>(coupons_.size()));
+ bytes[hll_constants::FLAGS_BYTE] = this->makeFlagsByte(compact);
+ bytes[hll_constants::LIST_COUNT_BYTE] = static_cast<uint8_t>(this->mode_ == LIST ? couponCount_ : 0);
+ bytes[hll_constants::MODE_BYTE] = this->makeModeByte();
if (this->mode_ == SET) {
- std::memcpy(bytes + HllUtil<A>::HASH_SET_COUNT_INT, &couponCount_, sizeof(couponCount_));
+ std::memcpy(bytes + hll_constants::HASH_SET_COUNT_INT, &couponCount_, sizeof(couponCount_));
}
// coupons
@@ -215,9 +215,9 @@
// header
const uint8_t preInts = getPreInts();
write(os, preInts);
- const uint8_t serialVersion(HllUtil<A>::SER_VER);
+ const uint8_t serialVersion(hll_constants::SER_VER);
write(os, serialVersion);
- const uint8_t familyId(HllUtil<A>::FAMILY_ID);
+ const uint8_t familyId(hll_constants::FAMILY_ID);
write(os, familyId);
const uint8_t lgKByte = this->lgConfigK_;
write(os, lgKByte);
@@ -268,7 +268,7 @@
HllSketchImpl<A>* CouponList<A>::couponUpdate(uint32_t coupon) {
for (size_t i = 0; i < coupons_.size(); ++i) { // search for empty slot
const uint32_t couponAtIdx = coupons_[i];
- if (couponAtIdx == HllUtil<A>::EMPTY) {
+ if (couponAtIdx == hll_constants::EMPTY) {
coupons_[i] = coupon; // the actual update
++couponCount_;
if (couponCount_ == static_cast<uint32_t>(coupons_.size())) { // array full
@@ -301,7 +301,7 @@
double CouponList<A>::getLowerBound(uint8_t numStdDev) const {
HllUtil<A>::checkNumStdDev(numStdDev);
const double est = CubicInterpolation<A>::usingXAndYTables(couponCount_);
- const double tmp = est / (1.0 + (numStdDev * HllUtil<A>::COUPON_RSE));
+ const double tmp = est / (1.0 + (numStdDev * hll_constants::COUPON_RSE));
return fmax(tmp, couponCount_);
}
@@ -309,7 +309,7 @@
double CouponList<A>::getUpperBound(uint8_t numStdDev) const {
HllUtil<A>::checkNumStdDev(numStdDev);
const double est = CubicInterpolation<A>::usingXAndYTables(couponCount_);
- const double tmp = est / (1.0 - (numStdDev * HllUtil<A>::COUPON_RSE));
+ const double tmp = est / (1.0 - (numStdDev * hll_constants::COUPON_RSE));
return fmax(tmp, couponCount_);
}
@@ -333,12 +333,12 @@
template<typename A>
uint32_t CouponList<A>::getMemDataStart() const {
- return HllUtil<A>::LIST_INT_ARR_START;
+ return hll_constants::LIST_INT_ARR_START;
}
template<typename A>
uint8_t CouponList<A>::getPreInts() const {
- return HllUtil<A>::LIST_PREINTS;
+ return hll_constants::LIST_PREINTS;
}
template<typename A>
diff --git a/hll/include/Hll4Array-internal.hpp b/hll/include/Hll4Array-internal.hpp
index 070aae0..b0e09a7 100644
--- a/hll/include/Hll4Array-internal.hpp
+++ b/hll/include/Hll4Array-internal.hpp
@@ -82,11 +82,11 @@
AuxHashMap<A>* auxHashMap = getAuxHashMap();
uint32_t auxBytes;
if (auxHashMap == nullptr) {
- auxBytes = 4 << HllUtil<A>::LG_AUX_ARR_INTS[this->lgConfigK_];
+ auxBytes = 4 << hll_constants::LG_AUX_ARR_INTS[this->lgConfigK_];
} else {
auxBytes = 4 << auxHashMap->getLgAuxArrInts();
}
- return HllUtil<A>::HLL_BYTE_ARR_START + getHllByteArrBytes() + auxBytes;
+ return hll_constants::HLL_BYTE_ARR_START + getHllByteArrBytes() + auxBytes;
}
template<typename A>
@@ -110,13 +110,13 @@
if ((slotNo & 1) > 0) { // odd?
return byte >> 4;
}
- return byte & HllUtil<A>::loNibbleMask;
+ return byte & hll_constants::loNibbleMask;
}
template<typename A>
uint8_t Hll4Array<A>::get_value(uint32_t index) const {
const uint8_t value = getSlot(index);
- if (value != HllUtil<A>::AUX_TOKEN) return value + this->curMin_;
+ if (value != hll_constants::AUX_TOKEN) return value + this->curMin_;
return auxHashMap_->mustFindValueFor(index);
}
@@ -143,10 +143,10 @@
const uint8_t oldValue = this->hllByteArr_[byteno];
if ((slotNo & 1) == 0) { // set low nibble
this->hllByteArr_[byteno]
- = ((oldValue & HllUtil<A>::hiNibbleMask) | (newValue & HllUtil<A>::loNibbleMask));
+ = ((oldValue & hll_constants::hiNibbleMask) | (newValue & hll_constants::loNibbleMask));
} else { // set high nibble
this->hllByteArr_[byteno]
- = ((oldValue & HllUtil<A>::loNibbleMask) | ((newValue << 4) & HllUtil<A>::hiNibbleMask));
+ = ((oldValue & hll_constants::loNibbleMask) | ((newValue << 4) & hll_constants::hiNibbleMask));
}
}
@@ -161,7 +161,7 @@
if (newVal > lbOnOldValue) { // 842
// Note: if an AUX_TOKEN exists, then auxHashMap must already exist
// 846: rawStoredOldValue == AUX_TOKEN
- const uint8_t actualOldValue = (rawStoredOldValue < HllUtil<A>::AUX_TOKEN)
+ const uint8_t actualOldValue = (rawStoredOldValue < hll_constants::AUX_TOKEN)
? (lbOnOldValue) : (auxHashMap_->mustFindValueFor(slotNo));
if (newVal > actualOldValue) { // 848: actualOldValue could still be 0; newValue > 0
@@ -175,11 +175,11 @@
// and lgConfigK bounds do not allow overflowing an int
//assert(shiftedNewValue >= 0);
- if (rawStoredOldValue == HllUtil<A>::AUX_TOKEN) { // 879
+ if (rawStoredOldValue == hll_constants::AUX_TOKEN) { // 879
// Given that we have an AUX_TOKEN, there are 4 cases for how to
// actually modify the data structure
- if (shiftedNewValue >= HllUtil<A>::AUX_TOKEN) { // case 1: 881
+ if (shiftedNewValue >= hll_constants::AUX_TOKEN) { // case 1: 881
// the byte array already contains aux token
// This is the case where old and new values are both exceptions.
// The 4-bit array already is AUX_TOKEN, only need to update auxHashMap
@@ -190,13 +190,13 @@
// which is impossible given that curMin has not changed here and newVal > oldValue
}
} else { // rawStoredOldValue != AUX_TOKEN
- if (shiftedNewValue >= HllUtil<A>::AUX_TOKEN) { // case 3: 892
+ if (shiftedNewValue >= hll_constants::AUX_TOKEN) { // case 3: 892
// This is the case where the old value is not an exception and the new value is.
// The AUX_TOKEN must be stored in the 4-bit array and the new value
// added to the exception table
- putSlot(slotNo, HllUtil<A>::AUX_TOKEN);
+ putSlot(slotNo, hll_constants::AUX_TOKEN);
if (auxHashMap_ == nullptr) {
- auxHashMap_ = AuxHashMap<A>::newAuxHashMap(HllUtil<A>::LG_AUX_ARR_INTS[this->lgConfigK_],
+ auxHashMap_ = AuxHashMap<A>::newAuxHashMap(hll_constants::LG_AUX_ARR_INTS[this->lgConfigK_],
this->lgConfigK_, this->getAllocator());
}
auxHashMap_->mustAdd(slotNo, newVal);
@@ -245,7 +245,7 @@
if (oldStoredValue == 0) {
throw std::runtime_error("Array slots cannot be 0 at this point.");
}
- if (oldStoredValue < HllUtil<A>::AUX_TOKEN) {
+ if (oldStoredValue < hll_constants::AUX_TOKEN) {
putSlot(i, --oldStoredValue);
if (oldStoredValue == 0) { numAtNewCurMin++; }
} else { //oldStoredValue == AUX_TOKEN
@@ -272,11 +272,11 @@
throw std::logic_error("oldActualVal < newCurMin when incrementing curMin");
}
- if (getSlot(slotNum) != HllUtil<A>::AUX_TOKEN) {
+ if (getSlot(slotNum) != hll_constants::AUX_TOKEN) {
throw std::logic_error("getSlot(slotNum) != AUX_TOKEN for item in auxiliary hash map");
}
// Array slot != AUX_TOKEN at getSlot(slotNum);
- if (newShiftedVal < HllUtil<A>::AUX_TOKEN) { // 756
+ if (newShiftedVal < hll_constants::AUX_TOKEN) { // 756
if (newShiftedVal != 14) {
throw std::logic_error("newShiftedVal != 14 for item in old auxHashMap despite curMin increment");
}
@@ -287,7 +287,7 @@
} else { //newShiftedVal >= AUX_TOKEN
// the former exception remains an exception, so must be added to the newAuxMap
if (newAuxMap == nullptr) {
- newAuxMap = AuxHashMap<A>::newAuxHashMap(HllUtil<A>::LG_AUX_ARR_INTS[this->lgConfigK_],
+ newAuxMap = AuxHashMap<A>::newAuxHashMap(hll_constants::LG_AUX_ARR_INTS[this->lgConfigK_],
this->lgConfigK_, this->getAllocator());
}
newAuxMap->mustAdd(slotNum, oldActualVal);
diff --git a/hll/include/Hll6Array-internal.hpp b/hll/include/Hll6Array-internal.hpp
index 2d7ae9a..dccb82e 100644
--- a/hll/include/Hll6Array-internal.hpp
+++ b/hll/include/Hll6Array-internal.hpp
@@ -58,7 +58,7 @@
const uint32_t shift = startBit & 0x7;
const uint32_t byteIdx = startBit >> 3;
const uint16_t twoByteVal = (this->hllByteArr_[byteIdx + 1] << 8) | this->hllByteArr_[byteIdx];
- return (twoByteVal >> shift) & HllUtil<A>::VAL_MASK_6;
+ return (twoByteVal >> shift) & hll_constants::VAL_MASK_6;
}
template<typename A>
@@ -68,7 +68,7 @@
const uint32_t byteIdx = startBit >> 3;
const uint16_t valShifted = (value & 0x3F) << shift;
uint16_t curMasked = (this->hllByteArr_[byteIdx + 1] << 8) | this->hllByteArr_[byteIdx];
- curMasked &= (~(HllUtil<A>::VAL_MASK_6 << shift));
+ curMasked &= (~(hll_constants::VAL_MASK_6 << shift));
const uint16_t insert = curMasked | valShifted;
this->hllByteArr_[byteIdx] = insert & 0xFF;
this->hllByteArr_[byteIdx + 1] = (insert & 0xFF00) >> 8;
diff --git a/hll/include/HllArray-internal.hpp b/hll/include/HllArray-internal.hpp
index ed438f5..92524fb 100644
--- a/hll/include/HllArray-internal.hpp
+++ b/hll/include/HllArray-internal.hpp
@@ -62,54 +62,54 @@
template<typename A>
HllArray<A>* HllArray<A>::newHll(const void* bytes, size_t len, const A& allocator) {
- if (len < HllUtil<A>::HLL_BYTE_ARR_START) {
+ if (len < hll_constants::HLL_BYTE_ARR_START) {
throw std::out_of_range("Input data length insufficient to hold HLL array");
}
const uint8_t* data = static_cast<const uint8_t*>(bytes);
- if (data[HllUtil<A>::PREAMBLE_INTS_BYTE] != HllUtil<A>::HLL_PREINTS) {
+ if (data[hll_constants::PREAMBLE_INTS_BYTE] != hll_constants::HLL_PREINTS) {
throw std::invalid_argument("Incorrect number of preInts in input stream");
}
- if (data[HllUtil<A>::SER_VER_BYTE] != HllUtil<A>::SER_VER) {
+ if (data[hll_constants::SER_VER_BYTE] != hll_constants::SER_VER) {
throw std::invalid_argument("Wrong ser ver in input stream");
}
- if (data[HllUtil<A>::FAMILY_BYTE] != HllUtil<A>::FAMILY_ID) {
+ if (data[hll_constants::FAMILY_BYTE] != hll_constants::FAMILY_ID) {
throw std::invalid_argument("Input array is not an HLL sketch");
}
- const hll_mode mode = HllSketchImpl<A>::extractCurMode(data[HllUtil<A>::MODE_BYTE]);
+ const hll_mode mode = HllSketchImpl<A>::extractCurMode(data[hll_constants::MODE_BYTE]);
if (mode != HLL) {
- throw std::invalid_argument("Calling HLL array construtor with non-HLL mode data");
+ throw std::invalid_argument("Calling HLL array constructor with non-HLL mode data");
}
- const target_hll_type tgtHllType = HllSketchImpl<A>::extractTgtHllType(data[HllUtil<A>::MODE_BYTE]);
- const bool oooFlag = ((data[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::OUT_OF_ORDER_FLAG_MASK) ? true : false);
- const bool comapctFlag = ((data[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::COMPACT_FLAG_MASK) ? true : false);
- const bool startFullSizeFlag = ((data[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::FULL_SIZE_FLAG_MASK) ? true : false);
+ const target_hll_type tgtHllType = HllSketchImpl<A>::extractTgtHllType(data[hll_constants::MODE_BYTE]);
+ const bool oooFlag = ((data[hll_constants::FLAGS_BYTE] & hll_constants::OUT_OF_ORDER_FLAG_MASK) ? true : false);
+ const bool comapctFlag = ((data[hll_constants::FLAGS_BYTE] & hll_constants::COMPACT_FLAG_MASK) ? true : false);
+ const bool startFullSizeFlag = ((data[hll_constants::FLAGS_BYTE] & hll_constants::FULL_SIZE_FLAG_MASK) ? true : false);
- const uint8_t lgK = data[HllUtil<A>::LG_K_BYTE];
- const uint8_t curMin = data[HllUtil<A>::HLL_CUR_MIN_BYTE];
+ const uint8_t lgK = data[hll_constants::LG_K_BYTE];
+ const uint8_t curMin = data[hll_constants::HLL_CUR_MIN_BYTE];
const uint32_t arrayBytes = hllArrBytes(tgtHllType, lgK);
- if (len < static_cast<size_t>(HllUtil<A>::HLL_BYTE_ARR_START + arrayBytes)) {
+ if (len < static_cast<size_t>(hll_constants::HLL_BYTE_ARR_START + arrayBytes)) {
throw std::out_of_range("Input array too small to hold sketch image");
}
double hip, kxq0, kxq1;
- std::memcpy(&hip, data + HllUtil<A>::HIP_ACCUM_DOUBLE, sizeof(double));
- std::memcpy(&kxq0, data + HllUtil<A>::KXQ0_DOUBLE, sizeof(double));
- std::memcpy(&kxq1, data + HllUtil<A>::KXQ1_DOUBLE, sizeof(double));
+ std::memcpy(&hip, data + hll_constants::HIP_ACCUM_DOUBLE, sizeof(double));
+ std::memcpy(&kxq0, data + hll_constants::KXQ0_DOUBLE, sizeof(double));
+ std::memcpy(&kxq1, data + hll_constants::KXQ1_DOUBLE, sizeof(double));
uint32_t numAtCurMin, auxCount;
- std::memcpy(&numAtCurMin, data + HllUtil<A>::CUR_MIN_COUNT_INT, sizeof(int));
- std::memcpy(&auxCount, data + HllUtil<A>::AUX_COUNT_INT, sizeof(int));
+ std::memcpy(&numAtCurMin, data + hll_constants::CUR_MIN_COUNT_INT, sizeof(int));
+ std::memcpy(&auxCount, data + hll_constants::AUX_COUNT_INT, sizeof(int));
AuxHashMap<A>* auxHashMap = nullptr;
typedef std::unique_ptr<AuxHashMap<A>, std::function<void(AuxHashMap<A>*)>> aux_hash_map_ptr;
aux_hash_map_ptr aux_ptr;
if (auxCount > 0) { // necessarily TgtHllType == HLL_4
uint8_t auxLgIntArrSize = data[4];
- const size_t offset = HllUtil<A>::HLL_BYTE_ARR_START + arrayBytes;
+ const size_t offset = hll_constants::HLL_BYTE_ARR_START + arrayBytes;
const uint8_t* auxDataStart = data + offset;
auxHashMap = AuxHashMap<A>::deserialize(auxDataStart, len - offset, lgK, auxCount, auxLgIntArrSize, comapctFlag, allocator);
aux_ptr = aux_hash_map_ptr(auxHashMap, auxHashMap->make_deleter());
@@ -123,7 +123,7 @@
sketch->putKxQ1(kxq1);
sketch->putNumAtCurMin(numAtCurMin);
- std::memcpy(sketch->hllByteArr_.data(), data + HllUtil<A>::HLL_BYTE_ARR_START, arrayBytes);
+ std::memcpy(sketch->hllByteArr_.data(), data + hll_constants::HLL_BYTE_ARR_START, arrayBytes);
if (auxHashMap != nullptr)
((Hll4Array<A>*)sketch)->putAuxHashMap(auxHashMap);
@@ -137,28 +137,28 @@
uint8_t listHeader[8];
read(is, listHeader, 8 * sizeof(uint8_t));
- if (listHeader[HllUtil<A>::PREAMBLE_INTS_BYTE] != HllUtil<A>::HLL_PREINTS) {
+ if (listHeader[hll_constants::PREAMBLE_INTS_BYTE] != hll_constants::HLL_PREINTS) {
throw std::invalid_argument("Incorrect number of preInts in input stream");
}
- if (listHeader[HllUtil<A>::SER_VER_BYTE] != HllUtil<A>::SER_VER) {
+ if (listHeader[hll_constants::SER_VER_BYTE] != hll_constants::SER_VER) {
throw std::invalid_argument("Wrong ser ver in input stream");
}
- if (listHeader[HllUtil<A>::FAMILY_BYTE] != HllUtil<A>::FAMILY_ID) {
+ if (listHeader[hll_constants::FAMILY_BYTE] != hll_constants::FAMILY_ID) {
throw std::invalid_argument("Input stream is not an HLL sketch");
}
- hll_mode mode = HllSketchImpl<A>::extractCurMode(listHeader[HllUtil<A>::MODE_BYTE]);
+ hll_mode mode = HllSketchImpl<A>::extractCurMode(listHeader[hll_constants::MODE_BYTE]);
if (mode != HLL) {
throw std::invalid_argument("Calling HLL construtor with non-HLL mode data");
}
- const target_hll_type tgtHllType = HllSketchImpl<A>::extractTgtHllType(listHeader[HllUtil<A>::MODE_BYTE]);
- const bool oooFlag = ((listHeader[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::OUT_OF_ORDER_FLAG_MASK) ? true : false);
- const bool comapctFlag = ((listHeader[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::COMPACT_FLAG_MASK) ? true : false);
- const bool startFullSizeFlag = ((listHeader[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::FULL_SIZE_FLAG_MASK) ? true : false);
+ const target_hll_type tgtHllType = HllSketchImpl<A>::extractTgtHllType(listHeader[hll_constants::MODE_BYTE]);
+ const bool oooFlag = ((listHeader[hll_constants::FLAGS_BYTE] & hll_constants::OUT_OF_ORDER_FLAG_MASK) ? true : false);
+ const bool comapctFlag = ((listHeader[hll_constants::FLAGS_BYTE] & hll_constants::COMPACT_FLAG_MASK) ? true : false);
+ const bool startFullSizeFlag = ((listHeader[hll_constants::FLAGS_BYTE] & hll_constants::FULL_SIZE_FLAG_MASK) ? true : false);
- const uint8_t lgK = listHeader[HllUtil<A>::LG_K_BYTE];
- const uint8_t curMin = listHeader[HllUtil<A>::HLL_CUR_MIN_BYTE];
+ const uint8_t lgK = listHeader[hll_constants::LG_K_BYTE];
+ const uint8_t curMin = listHeader[hll_constants::HLL_CUR_MIN_BYTE];
HllArray* sketch = HllSketchImplFactory<A>::newHll(lgK, tgtHllType, startFullSizeFlag, allocator);
typedef std::unique_ptr<HllArray<A>, std::function<void(HllSketchImpl<A>*)>> hll_array_ptr;
@@ -198,21 +198,21 @@
uint8_t* bytes = byteArr.data() + header_size_bytes;
AuxHashMap<A>* auxHashMap = getAuxHashMap();
- bytes[HllUtil<A>::PREAMBLE_INTS_BYTE] = static_cast<uint8_t>(getPreInts());
- bytes[HllUtil<A>::SER_VER_BYTE] = static_cast<uint8_t>(HllUtil<A>::SER_VER);
- bytes[HllUtil<A>::FAMILY_BYTE] = static_cast<uint8_t>(HllUtil<A>::FAMILY_ID);
- bytes[HllUtil<A>::LG_K_BYTE] = static_cast<uint8_t>(this->lgConfigK_);
- bytes[HllUtil<A>::LG_ARR_BYTE] = static_cast<uint8_t>(auxHashMap == nullptr ? 0 : auxHashMap->getLgAuxArrInts());
- bytes[HllUtil<A>::FLAGS_BYTE] = this->makeFlagsByte(compact);
- bytes[HllUtil<A>::HLL_CUR_MIN_BYTE] = static_cast<uint8_t>(curMin_);
- bytes[HllUtil<A>::MODE_BYTE] = this->makeModeByte();
+ bytes[hll_constants::PREAMBLE_INTS_BYTE] = static_cast<uint8_t>(getPreInts());
+ bytes[hll_constants::SER_VER_BYTE] = static_cast<uint8_t>(hll_constants::SER_VER);
+ bytes[hll_constants::FAMILY_BYTE] = static_cast<uint8_t>(hll_constants::FAMILY_ID);
+ bytes[hll_constants::LG_K_BYTE] = static_cast<uint8_t>(this->lgConfigK_);
+ bytes[hll_constants::LG_ARR_BYTE] = static_cast<uint8_t>(auxHashMap == nullptr ? 0 : auxHashMap->getLgAuxArrInts());
+ bytes[hll_constants::FLAGS_BYTE] = this->makeFlagsByte(compact);
+ bytes[hll_constants::HLL_CUR_MIN_BYTE] = static_cast<uint8_t>(curMin_);
+ bytes[hll_constants::MODE_BYTE] = this->makeModeByte();
- std::memcpy(bytes + HllUtil<A>::HIP_ACCUM_DOUBLE, &hipAccum_, sizeof(double));
- std::memcpy(bytes + HllUtil<A>::KXQ0_DOUBLE, &kxq0_, sizeof(double));
- std::memcpy(bytes + HllUtil<A>::KXQ1_DOUBLE, &kxq1_, sizeof(double));
- std::memcpy(bytes + HllUtil<A>::CUR_MIN_COUNT_INT, &numAtCurMin_, sizeof(uint32_t));
+ std::memcpy(bytes + hll_constants::HIP_ACCUM_DOUBLE, &hipAccum_, sizeof(double));
+ std::memcpy(bytes + hll_constants::KXQ0_DOUBLE, &kxq0_, sizeof(double));
+ std::memcpy(bytes + hll_constants::KXQ1_DOUBLE, &kxq1_, sizeof(double));
+ std::memcpy(bytes + hll_constants::CUR_MIN_COUNT_INT, &numAtCurMin_, sizeof(uint32_t));
const uint32_t auxCount = (auxHashMap == nullptr ? 0 : auxHashMap->getAuxCount());
- std::memcpy(bytes + HllUtil<A>::AUX_COUNT_INT, &auxCount, sizeof(uint32_t));
+ std::memcpy(bytes + hll_constants::AUX_COUNT_INT, &auxCount, sizeof(uint32_t));
const uint32_t hllByteArrBytes = getHllByteArrBytes();
std::memcpy(bytes + getMemDataStart(), hllByteArr_.data(), hllByteArrBytes);
@@ -231,7 +231,7 @@
}
} else if (!compact) {
// if updatable, we write even if currently unused so the binary can be wrapped
- uint32_t auxBytes = 4 << HllUtil<A>::LG_AUX_ARR_INTS[this->lgConfigK_];
+ uint32_t auxBytes = 4 << hll_constants::LG_AUX_ARR_INTS[this->lgConfigK_];
std::fill_n(bytes, auxBytes, static_cast<uint8_t>(0));
}
}
@@ -244,9 +244,9 @@
// header
const uint8_t preInts = getPreInts();
write(os, preInts);
- const uint8_t serialVersion = HllUtil<A>::SER_VER;
+ const uint8_t serialVersion = hll_constants::SER_VER;
write(os, serialVersion);
- const uint8_t familyId = HllUtil<A>::FAMILY_ID;
+ const uint8_t familyId = hll_constants::FAMILY_ID;
write(os, familyId);
const uint8_t lgKByte = this->lgConfigK_;
write(os, lgKByte);
@@ -288,7 +288,7 @@
}
} else if (!compact) {
// if updatable, we write even if currently unused so the binary can be wrapped
- uint32_t auxBytes = 4 << HllUtil<A>::LG_AUX_ARR_INTS[this->lgConfigK_];
+ uint32_t auxBytes = 4 << hll_constants::LG_AUX_ARR_INTS[this->lgConfigK_];
std::fill_n(std::ostreambuf_iterator<char>(os), auxBytes, static_cast<char>(0));
}
}
@@ -327,10 +327,10 @@
double rseFactor;
if (oooFlag_) {
estimate = getCompositeEstimate();
- rseFactor = HllUtil<A>::HLL_NON_HIP_RSE_FACTOR;
+ rseFactor = hll_constants::HLL_NON_HIP_RSE_FACTOR;
} else {
estimate = hipAccum_;
- rseFactor = HllUtil<A>::HLL_HIP_RSE_FACTOR;
+ rseFactor = hll_constants::HLL_HIP_RSE_FACTOR;
}
double relErr;
@@ -351,10 +351,10 @@
double rseFactor;
if (oooFlag_) {
estimate = getCompositeEstimate();
- rseFactor = HllUtil<A>::HLL_NON_HIP_RSE_FACTOR;
+ rseFactor = hll_constants::HLL_NON_HIP_RSE_FACTOR;
} else {
estimate = hipAccum_;
- rseFactor = HllUtil<A>::HLL_HIP_RSE_FACTOR;
+ rseFactor = hll_constants::HLL_HIP_RSE_FACTOR;
}
double relErr;
@@ -531,24 +531,24 @@
template<typename A>
uint32_t HllArray<A>::getMemDataStart() const {
- return HllUtil<A>::HLL_BYTE_ARR_START;
+ return hll_constants::HLL_BYTE_ARR_START;
}
template<typename A>
uint32_t HllArray<A>::getUpdatableSerializationBytes() const {
- return HllUtil<A>::HLL_BYTE_ARR_START + getHllByteArrBytes();
+ return hll_constants::HLL_BYTE_ARR_START + getHllByteArrBytes();
}
template<typename A>
uint32_t HllArray<A>::getCompactSerializationBytes() const {
AuxHashMap<A>* auxHashMap = getAuxHashMap();
const uint32_t auxCountBytes = ((auxHashMap == nullptr) ? 0 : auxHashMap->getCompactSizeBytes());
- return HllUtil<A>::HLL_BYTE_ARR_START + getHllByteArrBytes() + auxCountBytes;
+ return hll_constants::HLL_BYTE_ARR_START + getHllByteArrBytes() + auxCountBytes;
}
template<typename A>
uint8_t HllArray<A>::getPreInts() const {
- return HllUtil<A>::HLL_PREINTS;
+ return hll_constants::HLL_PREINTS;
}
template<typename A>
@@ -617,7 +617,7 @@
{
while (index_ < array_size_) {
value_ = get_value(array_, index_, hll_type_, exceptions_, offset_);
- if (all_ || value_ != HllUtil<A>::EMPTY) break;
+ if (all_ || value_ != hll_constants::EMPTY) break;
++index_;
}
}
@@ -626,7 +626,7 @@
typename HllArray<A>::const_iterator& HllArray<A>::const_iterator::operator++() {
while (++index_ < array_size_) {
value_ = get_value(array_, index_, hll_type_, exceptions_, offset_);
- if (all_ || value_ != HllUtil<A>::EMPTY) break;
+ if (all_ || value_ != hll_constants::EMPTY) break;
}
return *this;
}
@@ -648,9 +648,9 @@
if ((index & 1) > 0) { // odd
value >>= 4;
} else {
- value &= HllUtil<A>::loNibbleMask;
+ value &= hll_constants::loNibbleMask;
}
- if (value == HllUtil<A>::AUX_TOKEN) { // exception
+ if (value == hll_constants::AUX_TOKEN) { // exception
return exceptions->mustFindValueFor(index);
}
return value + offset;
@@ -659,7 +659,7 @@
const uint8_t shift = start_bit & 0x7;
const size_t byte_idx = start_bit >> 3;
const uint16_t two_byte_val = (array[byte_idx + 1] << 8) | array[byte_idx];
- return (two_byte_val >> shift) & HllUtil<A>::VAL_MASK_6;
+ return (two_byte_val >> shift) & hll_constants::VAL_MASK_6;
}
// HLL_8
return array[index];
diff --git a/hll/include/HllSketch-internal.hpp b/hll/include/HllSketch-internal.hpp
index 08f1c07..80e6887 100644
--- a/hll/include/HllSketch-internal.hpp
+++ b/hll/include/HllSketch-internal.hpp
@@ -213,7 +213,7 @@
template<typename A>
void hll_sketch_alloc<A>::coupon_update(uint32_t coupon) {
- if (coupon == HllUtil<A>::EMPTY) { return; }
+ if (coupon == hll_constants::EMPTY) { return; }
HllSketchImpl<A>* result = this->sketch_impl->couponUpdate(coupon);
if (result != this->sketch_impl) {
this->sketch_impl->get_deleter()(this->sketch_impl);
@@ -439,14 +439,14 @@
const target_hll_type tgtHllType) {
uint32_t arrBytes;
if (tgtHllType == target_hll_type::HLL_4) {
- const uint32_t auxBytes = 4 << HllUtil<A>::LG_AUX_ARR_INTS[lg_config_k];
+ const uint32_t auxBytes = 4 << hll_constants::LG_AUX_ARR_INTS[lg_config_k];
arrBytes = HllArray<A>::hll4ArrBytes(lg_config_k) + auxBytes;
} else if (tgtHllType == target_hll_type::HLL_6) {
arrBytes = HllArray<A>::hll6ArrBytes(lg_config_k);
} else { //HLL_8
arrBytes = HllArray<A>::hll8ArrBytes(lg_config_k);
}
- return HllUtil<A>::HLL_BYTE_ARR_START + arrBytes;
+ return hll_constants::HLL_BYTE_ARR_START + arrBytes;
}
template<typename A>
diff --git a/hll/include/HllSketchImpl-internal.hpp b/hll/include/HllSketchImpl-internal.hpp
index 5db7965..89ae4e6 100644
--- a/hll/include/HllSketchImpl-internal.hpp
+++ b/hll/include/HllSketchImpl-internal.hpp
@@ -70,10 +70,10 @@
template<typename A>
uint8_t HllSketchImpl<A>::makeFlagsByte(bool compact) const {
uint8_t flags = 0;
- flags |= (isEmpty() ? HllUtil<A>::EMPTY_FLAG_MASK : 0);
- flags |= (compact ? HllUtil<A>::COMPACT_FLAG_MASK : 0);
- flags |= (isOutOfOrderFlag() ? HllUtil<A>::OUT_OF_ORDER_FLAG_MASK : 0);
- flags |= (startFullSize_ ? HllUtil<A>::FULL_SIZE_FLAG_MASK : 0);
+ flags |= (isEmpty() ? hll_constants::EMPTY_FLAG_MASK : 0);
+ flags |= (compact ? hll_constants::COMPACT_FLAG_MASK : 0);
+ flags |= (isOutOfOrderFlag() ? hll_constants::OUT_OF_ORDER_FLAG_MASK : 0);
+ flags |= (startFullSize_ ? hll_constants::FULL_SIZE_FLAG_MASK : 0);
return flags;
}
diff --git a/hll/include/HllSketchImplFactory.hpp b/hll/include/HllSketchImplFactory.hpp
index 5baa656..446d712 100644
--- a/hll/include/HllSketchImplFactory.hpp
+++ b/hll/include/HllSketchImplFactory.hpp
@@ -76,11 +76,11 @@
// we'll hand off the sketch based on PreInts so we don't need
// to move the stream pointer back and forth -- perhaps somewhat fragile?
const uint8_t preInts = static_cast<uint8_t>(is.peek());
- if (preInts == HllUtil<A>::HLL_PREINTS) {
+ if (preInts == hll_constants::HLL_PREINTS) {
return HllArray<A>::newHll(is, allocator);
- } else if (preInts == HllUtil<A>::HASH_SET_PREINTS) {
+ } else if (preInts == hll_constants::HASH_SET_PREINTS) {
return CouponHashSet<A>::newSet(is, allocator);
- } else if (preInts == HllUtil<A>::LIST_PREINTS) {
+ } else if (preInts == hll_constants::LIST_PREINTS) {
return CouponList<A>::newList(is, allocator);
} else {
throw std::invalid_argument("Attempt to deserialize unknown object type");
@@ -91,11 +91,11 @@
HllSketchImpl<A>* HllSketchImplFactory<A>::deserialize(const void* bytes, size_t len, const A& allocator) {
// read current mode directly
const uint8_t preInts = static_cast<const uint8_t*>(bytes)[0];
- if (preInts == HllUtil<A>::HLL_PREINTS) {
+ if (preInts == hll_constants::HLL_PREINTS) {
return HllArray<A>::newHll(bytes, len, allocator);
- } else if (preInts == HllUtil<A>::HASH_SET_PREINTS) {
+ } else if (preInts == hll_constants::HASH_SET_PREINTS) {
return CouponHashSet<A>::newSet(bytes, len, allocator);
- } else if (preInts == HllUtil<A>::LIST_PREINTS) {
+ } else if (preInts == hll_constants::LIST_PREINTS) {
return CouponList<A>::newList(bytes, len, allocator);
} else {
throw std::invalid_argument("Attempt to deserialize unknown object type");
diff --git a/hll/include/HllUtil.hpp b/hll/include/HllUtil.hpp
index 8a02664..a78dd83 100644
--- a/hll/include/HllUtil.hpp
+++ b/hll/include/HllUtil.hpp
@@ -34,76 +34,86 @@
enum hll_mode { LIST = 0, SET, HLL };
+namespace hll_constants {
+
+// preamble stuff
+static const uint8_t SER_VER = 1;
+static const uint8_t FAMILY_ID = 7;
+
+static const uint8_t EMPTY_FLAG_MASK = 4;
+static const uint8_t COMPACT_FLAG_MASK = 8;
+static const uint8_t OUT_OF_ORDER_FLAG_MASK = 16;
+static const uint8_t FULL_SIZE_FLAG_MASK = 32;
+
+static const uint32_t PREAMBLE_INTS_BYTE = 0;
+static const uint32_t SER_VER_BYTE = 1;
+static const uint32_t FAMILY_BYTE = 2;
+static const uint32_t LG_K_BYTE = 3;
+static const uint32_t LG_ARR_BYTE = 4;
+static const uint32_t FLAGS_BYTE = 5;
+static const uint32_t LIST_COUNT_BYTE = 6;
+static const uint32_t HLL_CUR_MIN_BYTE = 6;
+static const uint32_t MODE_BYTE = 7; // lo2bits = curMode, next 2 bits = tgtHllMode
+
+// Coupon List
+static const uint32_t LIST_INT_ARR_START = 8;
+static const uint8_t LIST_PREINTS = 2;
+// Coupon Hash Set
+static const uint32_t HASH_SET_COUNT_INT = 8;
+static const uint32_t HASH_SET_INT_ARR_START = 12;
+static const uint8_t HASH_SET_PREINTS = 3;
+// HLL
+static const uint8_t HLL_PREINTS = 10;
+static const uint32_t HLL_BYTE_ARR_START = 40;
+static const uint32_t HIP_ACCUM_DOUBLE = 8;
+static const uint32_t KXQ0_DOUBLE = 16;
+static const uint32_t KXQ1_DOUBLE = 24;
+static const uint32_t CUR_MIN_COUNT_INT = 32;
+static const uint32_t AUX_COUNT_INT = 36;
+
+static const uint32_t EMPTY_SKETCH_SIZE_BYTES = 8;
+
+// other HllUtil stuff
+static const uint8_t KEY_BITS_26 = 26;
+static const uint8_t VAL_BITS_6 = 6;
+static const uint32_t KEY_MASK_26 = (1 << KEY_BITS_26) - 1;
+static const uint32_t VAL_MASK_6 = (1 << VAL_BITS_6) - 1;
+static const uint32_t EMPTY = 0;
+static const uint8_t MIN_LOG_K = 4;
+static const uint8_t MAX_LOG_K = 21;
+
+static const double HLL_HIP_RSE_FACTOR = 0.8325546; // sqrt(ln(2))
+static const double HLL_NON_HIP_RSE_FACTOR = 1.03896; // sqrt((3 * ln(2)) - 1)
+static const double COUPON_RSE_FACTOR = 0.409; // at transition point not the asymptote
+static const double COUPON_RSE = COUPON_RSE_FACTOR / (1 << 13);
+
+static const uint8_t LG_INIT_LIST_SIZE = 3;
+static const uint8_t LG_INIT_SET_SIZE = 5;
+static const uint32_t RESIZE_NUMER = 3;
+static const uint32_t RESIZE_DENOM = 4;
+
+static const uint8_t loNibbleMask = 0x0f;
+static const uint8_t hiNibbleMask = 0xf0;
+static const uint8_t AUX_TOKEN = 0xf;
+
+/**
+* Log2 table sizes for exceptions based on lgK from 0 to 26.
+* However, only lgK from 4 to 21 are used.
+*/
+static const uint8_t LG_AUX_ARR_INTS[] = {
+ 0, 2, 2, 2, 2, 2, 2, 3, 3, 3, // 0 - 9
+ 4, 4, 5, 5, 6, 7, 8, 9, 10, 11, // 10-19
+ 12, 13, 14, 15, 16, 17, 18 // 20-26
+};
+
+} // namespace hll_constants
+
+
// template provides internal consistency and allows static float values
// but we don't use the template parameter anywhere
template<typename A = std::allocator<uint8_t> >
class HllUtil final {
public:
- // preamble stuff
- static const uint8_t SER_VER = 1;
- static const uint8_t FAMILY_ID = 7;
-
- static const uint8_t EMPTY_FLAG_MASK = 4;
- static const uint8_t COMPACT_FLAG_MASK = 8;
- static const uint8_t OUT_OF_ORDER_FLAG_MASK = 16;
- static const uint8_t FULL_SIZE_FLAG_MASK = 32;
-
- static const uint32_t PREAMBLE_INTS_BYTE = 0;
- static const uint32_t SER_VER_BYTE = 1;
- static const uint32_t FAMILY_BYTE = 2;
- static const uint32_t LG_K_BYTE = 3;
- static const uint32_t LG_ARR_BYTE = 4;
- static const uint32_t FLAGS_BYTE = 5;
- static const uint32_t LIST_COUNT_BYTE = 6;
- static const uint32_t HLL_CUR_MIN_BYTE = 6;
- static const uint32_t MODE_BYTE = 7; // lo2bits = curMode, next 2 bits = tgtHllMode
-
- // Coupon List
- static const uint32_t LIST_INT_ARR_START = 8;
- static const uint8_t LIST_PREINTS = 2;
- // Coupon Hash Set
- static const uint32_t HASH_SET_COUNT_INT = 8;
- static const uint32_t HASH_SET_INT_ARR_START = 12;
- static const uint8_t HASH_SET_PREINTS = 3;
- // HLL
- static const uint8_t HLL_PREINTS = 10;
- static const uint32_t HLL_BYTE_ARR_START = 40;
- static const uint32_t HIP_ACCUM_DOUBLE = 8;
- static const uint32_t KXQ0_DOUBLE = 16;
- static const uint32_t KXQ1_DOUBLE = 24;
- static const uint32_t CUR_MIN_COUNT_INT = 32;
- static const uint32_t AUX_COUNT_INT = 36;
-
- static const uint32_t EMPTY_SKETCH_SIZE_BYTES = 8;
-
- // other HllUtil stuff
- static const uint8_t KEY_BITS_26 = 26;
- static const uint8_t VAL_BITS_6 = 6;
- static const uint32_t KEY_MASK_26 = (1 << KEY_BITS_26) - 1;
- static const uint32_t VAL_MASK_6 = (1 << VAL_BITS_6) - 1;
- static const uint32_t EMPTY = 0;
- static const uint8_t MIN_LOG_K = 4;
- static const uint8_t MAX_LOG_K = 21;
-
- static const double HLL_HIP_RSE_FACTOR; // sqrt(log(2.0)) = 0.8325546
- static const double HLL_NON_HIP_RSE_FACTOR; // sqrt((3.0 * log(2.0)) - 1.0) = 1.03896
- static const double COUPON_RSE_FACTOR; // 0.409 at transition point not the asymptote
- static const double COUPON_RSE; // COUPON_RSE_FACTOR / (1 << 13);
-
- static const uint8_t LG_INIT_LIST_SIZE = 3;
- static const uint8_t LG_INIT_SET_SIZE = 5;
- static const uint32_t RESIZE_NUMER = 3;
- static const uint32_t RESIZE_DENOM = 4;
-
- static const uint8_t loNibbleMask = 0x0f;
- static const uint8_t hiNibbleMask = 0xf0;
- static const uint8_t AUX_TOKEN = 0xf;
-
- /**
- * Log2 table sizes for exceptions based on lgK from 0 to 26.
- * However, only lgK from 4 to 21 are used.
- */
- static const uint8_t LG_AUX_ARR_INTS[];
static uint32_t coupon(const uint64_t hash[]);
static uint32_t coupon(const HashState& hashState);
@@ -122,35 +132,19 @@
};
template<typename A>
-const double HllUtil<A>::HLL_HIP_RSE_FACTOR = sqrt(log(2.0)); // 0.8325546
-template<typename A>
-const double HllUtil<A>::HLL_NON_HIP_RSE_FACTOR = sqrt((3.0 * log(2.0)) - 1.0); // 1.03896
-template<typename A>
-const double HllUtil<A>::COUPON_RSE_FACTOR = 0.409;
-template<typename A>
-const double HllUtil<A>::COUPON_RSE = COUPON_RSE_FACTOR / (1 << 13);
-
-template<typename A>
-const uint8_t HllUtil<A>::LG_AUX_ARR_INTS[] = {
- 0, 2, 2, 2, 2, 2, 2, 3, 3, 3, // 0 - 9
- 4, 4, 5, 5, 6, 7, 8, 9, 10, 11, // 10-19
- 12, 13, 14, 15, 16, 17, 18 // 20-26
- };
-
-template<typename A>
inline uint32_t HllUtil<A>::coupon(const uint64_t hash[]) {
- uint32_t addr26 = hash[0] & KEY_MASK_26;
+ uint32_t addr26 = hash[0] & hll_constants::KEY_MASK_26;
uint8_t lz = count_leading_zeros_in_u64(hash[1]);
uint8_t value = ((lz > 62 ? 62 : lz) + 1);
- return (value << KEY_BITS_26) | addr26;
+ return (value << hll_constants::KEY_BITS_26) | addr26;
}
template<typename A>
inline uint32_t HllUtil<A>::coupon(const HashState& hashState) {
- uint32_t addr26 = (int) (hashState.h1 & KEY_MASK_26);
+ uint32_t addr26 = (int) (hashState.h1 & hll_constants::KEY_MASK_26);
uint8_t lz = count_leading_zeros_in_u64(hashState.h2);
uint8_t value = ((lz > 62 ? 62 : lz) + 1);
- return (value << KEY_BITS_26) | addr26;
+ return (value << hll_constants::KEY_BITS_26) | addr26;
}
template<typename A>
@@ -166,7 +160,7 @@
template<typename A>
inline uint8_t HllUtil<A>::checkLgK(uint8_t lgK) {
- if ((lgK >= HllUtil<A>::MIN_LOG_K) && (lgK <= HllUtil<A>::MAX_LOG_K)) {
+ if ((lgK >= hll_constants::MIN_LOG_K) && (lgK <= hll_constants::MAX_LOG_K)) {
return lgK;
} else {
throw std::invalid_argument("Invalid value of k: " + std::to_string(lgK));
@@ -189,17 +183,17 @@
template<typename A>
inline uint32_t HllUtil<A>::pair(uint32_t slotNo, uint8_t value) {
- return (value << HllUtil<A>::KEY_BITS_26) | (slotNo & HllUtil<A>::KEY_MASK_26);
+ return (value << hll_constants::KEY_BITS_26) | (slotNo & hll_constants::KEY_MASK_26);
}
template<typename A>
inline uint32_t HllUtil<A>::getLow26(uint32_t coupon) {
- return coupon & HllUtil<A>::KEY_MASK_26;
+ return coupon & hll_constants::KEY_MASK_26;
}
template<typename A>
inline uint8_t HllUtil<A>::getValue(uint32_t coupon) {
- return coupon >> HllUtil<A>::KEY_BITS_26;
+ return coupon >> hll_constants::KEY_BITS_26;
}
template<typename A>
@@ -223,14 +217,14 @@
template<typename A>
inline uint8_t HllUtil<A>::computeLgArrInts(hll_mode mode, uint32_t count, uint8_t lgConfigK) {
// assume value missing and recompute
- if (mode == LIST) { return HllUtil<A>::LG_INIT_LIST_SIZE; }
+ if (mode == LIST) { return hll_constants::LG_INIT_LIST_SIZE; }
uint32_t ceilPwr2 = ceiling_power_of_2(count);
- if ((HllUtil<A>::RESIZE_DENOM * count) > (HllUtil<A>::RESIZE_NUMER * ceilPwr2)) { ceilPwr2 <<= 1;}
+ if ((hll_constants::RESIZE_DENOM * count) > (hll_constants::RESIZE_NUMER * ceilPwr2)) { ceilPwr2 <<= 1;}
if (mode == SET) {
- return std::max(HllUtil<A>::LG_INIT_SET_SIZE, HllUtil<A>::simpleIntLog2(ceilPwr2));
+ return std::max(hll_constants::LG_INIT_SET_SIZE, HllUtil<A>::simpleIntLog2(ceilPwr2));
}
//only used for HLL4
- return std::max(HllUtil<A>::LG_AUX_ARR_INTS[lgConfigK], HllUtil<A>::simpleIntLog2(ceilPwr2));
+ return std::max(hll_constants::LG_AUX_ARR_INTS[lgConfigK], HllUtil<A>::simpleIntLog2(ceilPwr2));
}
}
diff --git a/hll/include/coupon_iterator-internal.hpp b/hll/include/coupon_iterator-internal.hpp
index 67e3733..67e912b 100644
--- a/hll/include/coupon_iterator-internal.hpp
+++ b/hll/include/coupon_iterator-internal.hpp
@@ -28,7 +28,7 @@
coupon_iterator<A>::coupon_iterator(const uint32_t* array, size_t array_size, size_t index, bool all):
array_(array), array_size_(array_size), index_(index), all_(all) {
while (index_ < array_size_) {
- if (all_ || array_[index_] != HllUtil<A>::EMPTY) break;
+ if (all_ || array_[index_] != hll_constants::EMPTY) break;
++index_;
}
}
@@ -36,7 +36,7 @@
template<typename A>
coupon_iterator<A>& coupon_iterator<A>::operator++() {
while (++index_ < array_size_) {
- if (all_ || array_[index_] != HllUtil<A>::EMPTY) break;
+ if (all_ || array_[index_] != hll_constants::EMPTY) break;
}
return *this;
}
diff --git a/hll/test/CouponHashSetTest.cpp b/hll/test/CouponHashSetTest.cpp
index 599b528..aa832b5 100644
--- a/hll/test/CouponHashSetTest.cpp
+++ b/hll/test/CouponHashSetTest.cpp
@@ -39,35 +39,35 @@
uint8_t* bytes = sketchBytes.data();
const size_t size = sketchBytes.size();
- bytes[HllUtil<>::PREAMBLE_INTS_BYTE] = 0;
+ bytes[hll_constants::PREAMBLE_INTS_BYTE] = 0;
// fail in HllSketchImpl
REQUIRE_THROWS_AS(hll_sketch::deserialize(bytes, size), std::invalid_argument);
// fail in CouponHashSet
REQUIRE_THROWS_AS(CouponHashSet<std::allocator<uint8_t>>::newSet(bytes, size, std::allocator<uint8_t>()), std::invalid_argument);
- bytes[HllUtil<>::PREAMBLE_INTS_BYTE] = HllUtil<>::HASH_SET_PREINTS;
+ bytes[hll_constants::PREAMBLE_INTS_BYTE] = hll_constants::HASH_SET_PREINTS;
- bytes[HllUtil<>::SER_VER_BYTE] = 0;
+ bytes[hll_constants::SER_VER_BYTE] = 0;
REQUIRE_THROWS_AS(hll_sketch::deserialize(bytes, size), std::invalid_argument);
- bytes[HllUtil<>::SER_VER_BYTE] = HllUtil<>::SER_VER;
+ bytes[hll_constants::SER_VER_BYTE] = hll_constants::SER_VER;
- bytes[HllUtil<>::FAMILY_BYTE] = 0;
+ bytes[hll_constants::FAMILY_BYTE] = 0;
REQUIRE_THROWS_AS(hll_sketch::deserialize(bytes, size), std::invalid_argument);
- bytes[HllUtil<>::FAMILY_BYTE] = HllUtil<>::FAMILY_ID;
+ bytes[hll_constants::FAMILY_BYTE] = hll_constants::FAMILY_ID;
- bytes[HllUtil<>::LG_K_BYTE] = 6;
+ bytes[hll_constants::LG_K_BYTE] = 6;
REQUIRE_THROWS_AS(hll_sketch::deserialize(bytes, size), std::invalid_argument);
- bytes[HllUtil<>::LG_K_BYTE] = lgK;
+ bytes[hll_constants::LG_K_BYTE] = lgK;
- uint8_t tmp = bytes[HllUtil<>::MODE_BYTE];
- bytes[HllUtil<>::MODE_BYTE] = 0x10; // HLL_6, LIST
+ uint8_t tmp = bytes[hll_constants::MODE_BYTE];
+ bytes[hll_constants::MODE_BYTE] = 0x10; // HLL_6, LIST
REQUIRE_THROWS_AS(hll_sketch::deserialize(bytes, size), std::invalid_argument);
- bytes[HllUtil<>::MODE_BYTE] = tmp;
+ bytes[hll_constants::MODE_BYTE] = tmp;
- tmp = bytes[HllUtil<>::LG_ARR_BYTE];
- bytes[HllUtil<>::LG_ARR_BYTE] = 0;
+ tmp = bytes[hll_constants::LG_ARR_BYTE];
+ bytes[hll_constants::LG_ARR_BYTE] = 0;
hll_sketch::deserialize(bytes, size);
// should work fine despite the corruption
- bytes[HllUtil<>::LG_ARR_BYTE] = tmp;
+ bytes[hll_constants::LG_ARR_BYTE] = tmp;
REQUIRE_THROWS_AS(hll_sketch::deserialize(bytes, size - 1), std::out_of_range);
REQUIRE_THROWS_AS(hll_sketch::deserialize(bytes, 3), std::out_of_range);
@@ -82,47 +82,47 @@
std::stringstream ss;
sk1.serialize_compact(ss);
- ss.seekp(HllUtil<>::PREAMBLE_INTS_BYTE);
+ ss.seekp(hll_constants::PREAMBLE_INTS_BYTE);
ss.put(0);
ss.seekg(0);
// fail in HllSketchImpl
REQUIRE_THROWS_AS(hll_sketch::deserialize(ss), std::invalid_argument);
// fail in CouponHashSet
REQUIRE_THROWS_AS(CouponHashSet<std::allocator<uint8_t>>::newSet(ss, std::allocator<uint8_t>()), std::invalid_argument);
- ss.seekp(HllUtil<>::PREAMBLE_INTS_BYTE);
- ss.put(HllUtil<>::HASH_SET_PREINTS);
+ ss.seekp(hll_constants::PREAMBLE_INTS_BYTE);
+ ss.put(hll_constants::HASH_SET_PREINTS);
- ss.seekp(HllUtil<>::SER_VER_BYTE);
+ ss.seekp(hll_constants::SER_VER_BYTE);
ss.put(0);
ss.seekg(0);
REQUIRE_THROWS_AS(hll_sketch::deserialize(ss), std::invalid_argument);
- ss.seekp(HllUtil<>::SER_VER_BYTE);
- ss.put(HllUtil<>::SER_VER);
+ ss.seekp(hll_constants::SER_VER_BYTE);
+ ss.put(hll_constants::SER_VER);
- ss.seekp(HllUtil<>::FAMILY_BYTE);
+ ss.seekp(hll_constants::FAMILY_BYTE);
ss.put(0);
ss.seekg(0);
REQUIRE_THROWS_AS(hll_sketch::deserialize(ss), std::invalid_argument);
- ss.seekp(HllUtil<>::FAMILY_BYTE);
- ss.put(HllUtil<>::FAMILY_ID);
+ ss.seekp(hll_constants::FAMILY_BYTE);
+ ss.put(hll_constants::FAMILY_ID);
- ss.seekg(HllUtil<>::MODE_BYTE);
+ ss.seekg(hll_constants::MODE_BYTE);
auto tmp = ss.get();
- ss.seekp(HllUtil<>::MODE_BYTE);
+ ss.seekp(hll_constants::MODE_BYTE);
ss.put(0x22); // HLL_8, HLL
ss.seekg(0);
REQUIRE_THROWS_AS(hll_sketch::deserialize(ss), std::invalid_argument);
- ss.seekp(HllUtil<>::MODE_BYTE);
+ ss.seekp(hll_constants::MODE_BYTE);
ss.put((char)tmp);
- ss.seekg(HllUtil<>::LG_ARR_BYTE);
+ ss.seekg(hll_constants::LG_ARR_BYTE);
tmp = ss.get();
- ss.seekp(HllUtil<>::LG_ARR_BYTE);
+ ss.seekp(hll_constants::LG_ARR_BYTE);
ss.put(0);
ss.seekg(0);
hll_sketch::deserialize(ss);
// should work fine despite the corruption
- ss.seekp(HllUtil<>::LG_ARR_BYTE);
+ ss.seekp(hll_constants::LG_ARR_BYTE);
ss.put((char)tmp);
}
diff --git a/hll/test/CouponListTest.cpp b/hll/test/CouponListTest.cpp
index 86b0dfd..a6c9333 100644
--- a/hll/test/CouponListTest.cpp
+++ b/hll/test/CouponListTest.cpp
@@ -118,24 +118,24 @@
uint8_t* bytes = sketchBytes.data();
const size_t size = sketchBytes.size();
- bytes[HllUtil<>::PREAMBLE_INTS_BYTE] = 0;
+ bytes[hll_constants::PREAMBLE_INTS_BYTE] = 0;
REQUIRE_THROWS_AS(hll_sketch::deserialize(bytes, size), std::invalid_argument);
REQUIRE_THROWS_AS(CouponList<std::allocator<uint8_t>>::newList(bytes, size, std::allocator<uint8_t>()), std::invalid_argument);
- bytes[HllUtil<>::PREAMBLE_INTS_BYTE] = HllUtil<>::LIST_PREINTS;
+ bytes[hll_constants::PREAMBLE_INTS_BYTE] = hll_constants::LIST_PREINTS;
- bytes[HllUtil<>::SER_VER_BYTE] = 0;
+ bytes[hll_constants::SER_VER_BYTE] = 0;
REQUIRE_THROWS_AS(hll_sketch::deserialize(bytes, size), std::invalid_argument);
- bytes[HllUtil<>::SER_VER_BYTE] = HllUtil<>::SER_VER;
+ bytes[hll_constants::SER_VER_BYTE] = hll_constants::SER_VER;
- bytes[HllUtil<>::FAMILY_BYTE] = 0;
+ bytes[hll_constants::FAMILY_BYTE] = 0;
REQUIRE_THROWS_AS(hll_sketch::deserialize(bytes, size), std::invalid_argument);
- bytes[HllUtil<>::FAMILY_BYTE] = HllUtil<>::FAMILY_ID;
+ bytes[hll_constants::FAMILY_BYTE] = hll_constants::FAMILY_ID;
- uint8_t tmp = bytes[HllUtil<>::MODE_BYTE];
- bytes[HllUtil<>::MODE_BYTE] = 0x01; // HLL_4, SET
+ uint8_t tmp = bytes[hll_constants::MODE_BYTE];
+ bytes[hll_constants::MODE_BYTE] = 0x01; // HLL_4, SET
REQUIRE_THROWS_AS(hll_sketch::deserialize(bytes, size), std::invalid_argument);
- bytes[HllUtil<>::MODE_BYTE] = tmp;
+ bytes[hll_constants::MODE_BYTE] = tmp;
REQUIRE_THROWS_AS(hll_sketch::deserialize(bytes, size - 1), std::out_of_range);
@@ -150,29 +150,29 @@
std::stringstream ss;
sk1.serialize_compact(ss);
- ss.seekp(HllUtil<>::PREAMBLE_INTS_BYTE);
+ ss.seekp(hll_constants::PREAMBLE_INTS_BYTE);
ss.put(0);
ss.seekg(0);
REQUIRE_THROWS_AS(hll_sketch::deserialize(ss), std::invalid_argument);
REQUIRE_THROWS_AS(CouponList<std::allocator<uint8_t>>::newList(ss, std::allocator<uint8_t>()), std::invalid_argument);
- ss.seekp(HllUtil<>::PREAMBLE_INTS_BYTE);
- ss.put(HllUtil<>::LIST_PREINTS);
+ ss.seekp(hll_constants::PREAMBLE_INTS_BYTE);
+ ss.put(hll_constants::LIST_PREINTS);
- ss.seekp(HllUtil<>::SER_VER_BYTE);
+ ss.seekp(hll_constants::SER_VER_BYTE);
ss.put(0);
ss.seekg(0);
REQUIRE_THROWS_AS(hll_sketch::deserialize(ss), std::invalid_argument);
- ss.seekp(HllUtil<>::SER_VER_BYTE);
- ss.put(HllUtil<>::SER_VER);
+ ss.seekp(hll_constants::SER_VER_BYTE);
+ ss.put(hll_constants::SER_VER);
- ss.seekp(HllUtil<>::FAMILY_BYTE);
+ ss.seekp(hll_constants::FAMILY_BYTE);
ss.put(0);
ss.seekg(0);
REQUIRE_THROWS_AS(hll_sketch::deserialize(ss), std::invalid_argument);
- ss.seekp(HllUtil<>::FAMILY_BYTE);
- ss.put(HllUtil<>::FAMILY_ID);
+ ss.seekp(hll_constants::FAMILY_BYTE);
+ ss.put(hll_constants::FAMILY_ID);
- ss.seekp(HllUtil<>::MODE_BYTE);
+ ss.seekp(hll_constants::MODE_BYTE);
ss.put(0x22); // HLL_8, HLL
ss.seekg(0);
REQUIRE_THROWS_AS(hll_sketch::deserialize(ss), std::invalid_argument);
diff --git a/hll/test/HllArrayTest.cpp b/hll/test/HllArrayTest.cpp
index ee001e9..ce39791 100644
--- a/hll/test/HllArrayTest.cpp
+++ b/hll/test/HllArrayTest.cpp
@@ -109,29 +109,29 @@
uint8_t* bytes = sketchBytes.data();
const size_t size = sketchBytes.size();
- bytes[HllUtil<>::PREAMBLE_INTS_BYTE] = 0;
+ bytes[hll_constants::PREAMBLE_INTS_BYTE] = 0;
REQUIRE_THROWS_AS(hll_sketch::deserialize(bytes, size), std::invalid_argument);
REQUIRE_THROWS_AS(HllArray<std::allocator<uint8_t>>::newHll(bytes, size, std::allocator<uint8_t>()), std::invalid_argument);
- bytes[HllUtil<>::PREAMBLE_INTS_BYTE] = HllUtil<>::HLL_PREINTS;
+ bytes[hll_constants::PREAMBLE_INTS_BYTE] = hll_constants::HLL_PREINTS;
- bytes[HllUtil<>::SER_VER_BYTE] = 0;
+ bytes[hll_constants::SER_VER_BYTE] = 0;
REQUIRE_THROWS_AS(hll_sketch::deserialize(bytes, size), std::invalid_argument);
- bytes[HllUtil<>::SER_VER_BYTE] = HllUtil<>::SER_VER;
+ bytes[hll_constants::SER_VER_BYTE] = hll_constants::SER_VER;
- bytes[HllUtil<>::FAMILY_BYTE] = 0;
+ bytes[hll_constants::FAMILY_BYTE] = 0;
REQUIRE_THROWS_AS(hll_sketch::deserialize(bytes, size), std::invalid_argument);
- bytes[HllUtil<>::FAMILY_BYTE] = HllUtil<>::FAMILY_ID;
+ bytes[hll_constants::FAMILY_BYTE] = hll_constants::FAMILY_ID;
- uint8_t tmp = bytes[HllUtil<>::MODE_BYTE];
- bytes[HllUtil<>::MODE_BYTE] = 0x10; // HLL_6, LIST
+ uint8_t tmp = bytes[hll_constants::MODE_BYTE];
+ bytes[hll_constants::MODE_BYTE] = 0x10; // HLL_6, LIST
REQUIRE_THROWS_AS(hll_sketch::deserialize(bytes, size), std::invalid_argument);
- bytes[HllUtil<>::MODE_BYTE] = tmp;
+ bytes[hll_constants::MODE_BYTE] = tmp;
- tmp = bytes[HllUtil<>::LG_ARR_BYTE];
- bytes[HllUtil<>::LG_ARR_BYTE] = 0;
+ tmp = bytes[hll_constants::LG_ARR_BYTE];
+ bytes[hll_constants::LG_ARR_BYTE] = 0;
hll_sketch::deserialize(bytes, size);
// should work fine despite the corruption
- bytes[HllUtil<>::LG_ARR_BYTE] = tmp;
+ bytes[hll_constants::LG_ARR_BYTE] = tmp;
REQUIRE_THROWS_AS(hll_sketch::deserialize(bytes, size - 1), std::out_of_range);
REQUIRE_THROWS_AS(hll_sketch::deserialize(bytes, 3), std::out_of_range);
@@ -146,45 +146,45 @@
std::stringstream ss;
sk1.serialize_compact(ss);
- ss.seekp(HllUtil<>::PREAMBLE_INTS_BYTE);
+ ss.seekp(hll_constants::PREAMBLE_INTS_BYTE);
ss.put(0);
ss.seekg(0);
REQUIRE_THROWS_AS(hll_sketch::deserialize(ss), std::invalid_argument);
REQUIRE_THROWS_AS(HllArray<std::allocator<uint8_t>>::newHll(ss, std::allocator<uint8_t>()), std::invalid_argument);
- ss.seekp(HllUtil<>::PREAMBLE_INTS_BYTE);
- ss.put(HllUtil<>::HLL_PREINTS);
+ ss.seekp(hll_constants::PREAMBLE_INTS_BYTE);
+ ss.put(hll_constants::HLL_PREINTS);
- ss.seekp(HllUtil<>::SER_VER_BYTE);
+ ss.seekp(hll_constants::SER_VER_BYTE);
ss.put(0);
ss.seekg(0);
REQUIRE_THROWS_AS(hll_sketch::deserialize(ss), std::invalid_argument);
- ss.seekp(HllUtil<>::SER_VER_BYTE);
- ss.put(HllUtil<>::SER_VER);
+ ss.seekp(hll_constants::SER_VER_BYTE);
+ ss.put(hll_constants::SER_VER);
- ss.seekp(HllUtil<>::FAMILY_BYTE);
+ ss.seekp(hll_constants::FAMILY_BYTE);
ss.put(0);
ss.seekg(0);
REQUIRE_THROWS_AS(hll_sketch::deserialize(ss), std::invalid_argument);
- ss.seekp(HllUtil<>::FAMILY_BYTE);
- ss.put(HllUtil<>::FAMILY_ID);
+ ss.seekp(hll_constants::FAMILY_BYTE);
+ ss.put(hll_constants::FAMILY_ID);
- ss.seekg(HllUtil<>::MODE_BYTE);
+ ss.seekg(hll_constants::MODE_BYTE);
auto tmp = ss.get();
- ss.seekp(HllUtil<>::MODE_BYTE);
+ ss.seekp(hll_constants::MODE_BYTE);
ss.put(0x11); // HLL_6, SET
ss.seekg(0);
REQUIRE_THROWS_AS(hll_sketch::deserialize(ss), std::invalid_argument);
- ss.seekp(HllUtil<>::MODE_BYTE);
+ ss.seekp(hll_constants::MODE_BYTE);
ss.put((char)tmp);
- ss.seekg(HllUtil<>::LG_ARR_BYTE);
+ ss.seekg(hll_constants::LG_ARR_BYTE);
tmp = ss.get();
- ss.seekp(HllUtil<>::LG_ARR_BYTE);
+ ss.seekp(hll_constants::LG_ARR_BYTE);
ss.put(0);
ss.seekg(0);
hll_sketch::deserialize(ss);
// should work fine despite the corruption
- ss.seekp(HllUtil<>::LG_ARR_BYTE);
+ ss.seekp(hll_constants::LG_ARR_BYTE);
ss.put((char)tmp);
}
diff --git a/hll/test/HllSketchTest.cpp b/hll/test/HllSketchTest.cpp
index c89845f..b0635d8 100644
--- a/hll/test/HllSketchTest.cpp
+++ b/hll/test/HllSketchTest.cpp
@@ -124,7 +124,7 @@
sk.update(24); // HLL
REQUIRE(sk.get_updatable_serialization_bytes() == 40 + 256);
- const auto hllBytes = HllUtil<>::HLL_BYTE_ARR_START + (1 << lgConfigK);
+ const auto hllBytes = hll_constants::HLL_BYTE_ARR_START + (1 << lgConfigK);
REQUIRE(sk.get_compact_serialization_bytes() == hllBytes);
REQUIRE(hll_sketch::get_max_updatable_serialization_bytes(lgConfigK, HLL_8) == hllBytes);
}
@@ -141,16 +141,16 @@
// LIST
for (i = 0; i < 7; ++i) { sk.update(i); }
- auto expected = HllUtil<>::LIST_INT_ARR_START + (i << 2);
+ auto expected = hll_constants::LIST_INT_ARR_START + (i << 2);
REQUIRE(sk.get_compact_serialization_bytes() == expected);
- expected = HllUtil<>::LIST_INT_ARR_START + (4 << HllUtil<>::LG_INIT_LIST_SIZE);
+ expected = hll_constants::LIST_INT_ARR_START + (4 << hll_constants::LG_INIT_LIST_SIZE);
REQUIRE(sk.get_updatable_serialization_bytes() == expected);
// SET
for (i = 7; i < 24; ++i) { sk.update(i); }
- expected = HllUtil<>::HASH_SET_INT_ARR_START + (i << 2);
+ expected = hll_constants::HASH_SET_INT_ARR_START + (i << 2);
REQUIRE(sk.get_compact_serialization_bytes() == expected);
- expected = HllUtil<>::HASH_SET_INT_ARR_START + (4 << HllUtil<>::LG_INIT_SET_SIZE);
+ expected = hll_constants::HASH_SET_INT_ARR_START + (4 << hll_constants::LG_INIT_SET_SIZE);
REQUIRE(sk.get_updatable_serialization_bytes() == expected);
}
@@ -230,10 +230,10 @@
TEST_CASE("hll sketch: check k limits", "[hll_sketch]") {
test_allocator_total_bytes = 0;
{
- hll_sketch_test_alloc sketch1(HllUtil<>::MIN_LOG_K, target_hll_type::HLL_8, false, 0);
- hll_sketch_test_alloc sketch2(HllUtil<>::MAX_LOG_K, target_hll_type::HLL_4, false, 0);
- REQUIRE_THROWS_AS(hll_sketch_test_alloc(HllUtil<>::MIN_LOG_K - 1, target_hll_type::HLL_4, false, 0), std::invalid_argument);
- REQUIRE_THROWS_AS(hll_sketch_test_alloc(HllUtil<>::MAX_LOG_K + 1, target_hll_type::HLL_4, false, 0), std::invalid_argument);
+ hll_sketch_test_alloc sketch1(hll_constants::MIN_LOG_K, target_hll_type::HLL_8, false, 0);
+ hll_sketch_test_alloc sketch2(hll_constants::MAX_LOG_K, target_hll_type::HLL_4, false, 0);
+ REQUIRE_THROWS_AS(hll_sketch_test_alloc(hll_constants::MIN_LOG_K - 1, target_hll_type::HLL_4, false, 0), std::invalid_argument);
+ REQUIRE_THROWS_AS(hll_sketch_test_alloc(hll_constants::MAX_LOG_K + 1, target_hll_type::HLL_4, false, 0), std::invalid_argument);
}
REQUIRE(test_allocator_total_bytes == 0);
}
diff --git a/hll/test/HllUnionTest.cpp b/hll/test/HllUnionTest.cpp
index e148e11..e2f4448 100644
--- a/hll/test/HllUnionTest.cpp
+++ b/hll/test/HllUnionTest.cpp
@@ -180,9 +180,9 @@
}
TEST_CASE("hll union: check config k limits", "[hll_union]") {
- REQUIRE_THROWS_AS(hll_union(HllUtil<>::MIN_LOG_K - 1), std::invalid_argument);
+ REQUIRE_THROWS_AS(hll_union(hll_constants::MIN_LOG_K - 1), std::invalid_argument);
- REQUIRE_THROWS_AS(hll_union(HllUtil<>::MAX_LOG_K + 1), std::invalid_argument);
+ REQUIRE_THROWS_AS(hll_union(hll_constants::MAX_LOG_K + 1), std::invalid_argument);
}
static double getBound(int lgK, bool ub, bool oooFlag, int numStdDev, double est) {