types and casts
diff --git a/hll/include/AuxHashMap-internal.hpp b/hll/include/AuxHashMap-internal.hpp
index dbc7f84..f409793 100644
--- a/hll/include/AuxHashMap-internal.hpp
+++ b/hll/include/AuxHashMap-internal.hpp
@@ -26,15 +26,15 @@
namespace datasketches {
template<typename A>
-AuxHashMap<A>::AuxHashMap(int lgAuxArrInts, int lgConfigK, const A& allocator):
+AuxHashMap<A>::AuxHashMap(uint8_t lgAuxArrInts, uint8_t lgConfigK, const A& allocator):
lgConfigK(lgConfigK),
lgAuxArrInts(lgAuxArrInts),
auxCount(0),
-entries(1 << lgAuxArrInts, 0, allocator)
+entries(1ULL << lgAuxArrInts, 0, allocator)
{}
template<typename A>
-AuxHashMap<A>* AuxHashMap<A>::newAuxHashMap(int lgAuxArrInts, int lgConfigK, const A& allocator) {
+AuxHashMap<A>* AuxHashMap<A>::newAuxHashMap(uint8_t lgAuxArrInts, uint8_t lgConfigK, const A& allocator) {
return new (ahmAlloc(allocator).allocate(1)) AuxHashMap<A>(lgAuxArrInts, lgConfigK, allocator);
}
@@ -45,42 +45,42 @@
template<typename A>
AuxHashMap<A>* AuxHashMap<A>::deserialize(const void* bytes, size_t len,
- int lgConfigK,
- int auxCount, int lgAuxArrInts,
+ uint8_t lgConfigK,
+ uint32_t auxCount, uint8_t lgAuxArrInts,
bool srcCompact, const A& allocator) {
- int lgArrInts = lgAuxArrInts;
+ uint8_t lgArrInts = lgAuxArrInts;
if (srcCompact) { // early compact versions didn't use LgArr byte field so ignore input
lgArrInts = HllUtil<A>::computeLgArrInts(HLL, auxCount, lgConfigK);
} else { // updatable
lgArrInts = lgAuxArrInts;
}
- int configKmask = (1 << lgConfigK) - 1;
+ const uint32_t configKmask = (1 << lgConfigK) - 1;
AuxHashMap<A>* auxHashMap;
- const int* auxPtr = static_cast<const int*>(bytes);
+ const uint32_t* auxPtr = static_cast<const uint32_t*>(bytes);
if (srcCompact) {
if (len < auxCount * sizeof(int)) {
throw std::out_of_range("Input array too small to hold AuxHashMap image");
}
auxHashMap = new (ahmAlloc(allocator).allocate(1)) AuxHashMap<A>(lgArrInts, lgConfigK, allocator);
- for (int i = 0; i < auxCount; ++i) {
- int pair = auxPtr[i];
- int slotNo = HllUtil<A>::getLow26(pair) & configKmask;
- int value = HllUtil<A>::getValue(pair);
+ for (uint32_t i = 0; i < auxCount; ++i) {
+ const uint32_t pair = auxPtr[i];
+ const uint32_t slotNo = HllUtil<A>::getLow26(pair) & configKmask;
+ const uint8_t value = HllUtil<A>::getValue(pair);
auxHashMap->mustAdd(slotNo, value);
}
} else { // updatable
- int itemsToRead = 1 << lgAuxArrInts;
- if (len < itemsToRead * sizeof(int)) {
+ uint32_t itemsToRead = 1 << lgAuxArrInts;
+ if (len < itemsToRead * sizeof(uint32_t)) {
throw std::out_of_range("Input array too small to hold AuxHashMap image");
}
auxHashMap = new (ahmAlloc(allocator).allocate(1)) AuxHashMap<A>(lgArrInts, lgConfigK, allocator);
- for (int i = 0; i < itemsToRead; ++i) {
- int pair = auxPtr[i];
+ for (uint32_t i = 0; i < itemsToRead; ++i) {
+ const uint32_t pair = auxPtr[i];
if (pair == HllUtil<A>::EMPTY) { continue; }
- int slotNo = HllUtil<A>::getLow26(pair) & configKmask;
- int value = HllUtil<A>::getValue(pair);
+ const uint32_t slotNo = HllUtil<A>::getLow26(pair) & configKmask;
+ const uint8_t value = HllUtil<A>::getValue(pair);
auxHashMap->mustAdd(slotNo, value);
}
}
@@ -94,10 +94,10 @@
}
template<typename A>
-AuxHashMap<A>* AuxHashMap<A>::deserialize(std::istream& is, const int lgConfigK,
- const int auxCount, const int lgAuxArrInts,
- const bool srcCompact, const A& allocator) {
- int lgArrInts = lgAuxArrInts;
+AuxHashMap<A>* AuxHashMap<A>::deserialize(std::istream& is, uint8_t lgConfigK,
+ uint32_t auxCount, uint8_t lgAuxArrInts,
+ bool srcCompact, const A& allocator) {
+ uint8_t lgArrInts = lgAuxArrInts;
if (srcCompact) { // early compact versions didn't use LgArr byte field so ignore input
lgArrInts = HllUtil<A>::computeLgArrInts(HLL, auxCount, lgConfigK);
} else { // updatable
@@ -108,22 +108,22 @@
typedef std::unique_ptr<AuxHashMap<A>, std::function<void(AuxHashMap<A>*)>> aux_hash_map_ptr;
aux_hash_map_ptr aux_ptr(auxHashMap, auxHashMap->make_deleter());
- int configKmask = (1 << lgConfigK) - 1;
+ const uint32_t configKmask = (1 << lgConfigK) - 1;
if (srcCompact) {
- for (int i = 0; i < auxCount; ++i) {
+ for (uint32_t i = 0; i < auxCount; ++i) {
const auto pair = read<int>(is);
- int slotNo = HllUtil<A>::getLow26(pair) & configKmask;
- int value = HllUtil<A>::getValue(pair);
+ uint32_t slotNo = HllUtil<A>::getLow26(pair) & configKmask;
+ uint8_t value = HllUtil<A>::getValue(pair);
auxHashMap->mustAdd(slotNo, value);
}
} else { // updatable
- int itemsToRead = 1 << lgAuxArrInts;
- for (int i = 0; i < itemsToRead; ++i) {
+ 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; }
- int slotNo = HllUtil<A>::getLow26(pair) & configKmask;
- int value = HllUtil<A>::getValue(pair);
+ const uint32_t slotNo = HllUtil<A>::getLow26(pair) & configKmask;
+ const uint8_t value = HllUtil<A>::getValue(pair);
auxHashMap->mustAdd(slotNo, value);
}
}
@@ -151,34 +151,34 @@
}
template<typename A>
-int AuxHashMap<A>::getAuxCount() const {
+uint32_t AuxHashMap<A>::getAuxCount() const {
return auxCount;
}
template<typename A>
-int* AuxHashMap<A>::getAuxIntArr(){
+uint32_t* AuxHashMap<A>::getAuxIntArr(){
return entries.data();
}
template<typename A>
-int AuxHashMap<A>::getLgAuxArrInts() const {
+uint8_t AuxHashMap<A>::getLgAuxArrInts() const {
return lgAuxArrInts;
}
template<typename A>
-int AuxHashMap<A>::getCompactSizeBytes() const {
+uint32_t AuxHashMap<A>::getCompactSizeBytes() const {
return auxCount << 2;
}
template<typename A>
-int AuxHashMap<A>::getUpdatableSizeBytes() const {
+uint32_t AuxHashMap<A>::getUpdatableSizeBytes() const {
return 4 << lgAuxArrInts;
}
template<typename A>
-void AuxHashMap<A>::mustAdd(const int slotNo, const int value) {
- const int index = find(entries.data(), lgAuxArrInts, lgConfigK, slotNo);
- const int entry_pair = HllUtil<A>::pair(slotNo, value);
+void AuxHashMap<A>::mustAdd(uint32_t slotNo, uint8_t value) {
+ const int32_t index = find(entries.data(), lgAuxArrInts, lgConfigK, slotNo);
+ const uint32_t entry_pair = HllUtil<A>::pair(slotNo, value);
if (index >= 0) {
throw std::invalid_argument("Found a slotNo that should not be there: SlotNo: "
+ std::to_string(slotNo) + ", Value: " + std::to_string(value));
@@ -191,8 +191,8 @@
}
template<typename A>
-int AuxHashMap<A>::mustFindValueFor(const int slotNo) const {
- const int index = find(entries.data(), lgAuxArrInts, lgConfigK, slotNo);
+uint8_t AuxHashMap<A>::mustFindValueFor(uint32_t slotNo) const {
+ const int32_t index = find(entries.data(), lgAuxArrInts, lgConfigK, slotNo);
if (index >= 0) {
return HllUtil<A>::getValue(entries[index]);
}
@@ -201,8 +201,8 @@
}
template<typename A>
-void AuxHashMap<A>::mustReplace(const int slotNo, const int value) {
- const int idx = find(entries.data(), lgAuxArrInts, lgConfigK, slotNo);
+void AuxHashMap<A>::mustReplace(uint32_t slotNo, uint8_t value) {
+ const int32_t idx = find(entries.data(), lgAuxArrInts, lgConfigK, slotNo);
if (idx >= 0) {
entries[idx] = HllUtil<A>::pair(slotNo, value);
return;
@@ -225,10 +225,10 @@
const int newArrLen = 1 << ++lgAuxArrInts;
vector_int entries_new(newArrLen, 0, entries.get_allocator());
for (size_t i = 0; i < entries.size(); ++i) {
- const int fetched = entries[i];
+ const uint32_t fetched = entries[i];
if (fetched != HllUtil<A>::EMPTY) {
// find empty in new array
- const int idx = find(entries_new.data(), lgAuxArrInts, lgConfigK, fetched & configKmask);
+ const int32_t idx = find(entries_new.data(), lgAuxArrInts, lgConfigK, fetched & configKmask);
entries_new[~idx] = fetched;
}
}
@@ -241,21 +241,20 @@
//Continues searching.
//If the probe comes back to original index, throws an exception.
template<typename A>
-int AuxHashMap<A>::find(const int* auxArr, const int lgAuxArrInts, const int lgConfigK,
- const int slotNo) {
- const int auxArrMask = (1 << lgAuxArrInts) - 1;
- const int configKmask = (1 << lgConfigK) - 1;
- int probe = slotNo & auxArrMask;
- const int loopIndex = probe;
+int32_t AuxHashMap<A>::find(const uint32_t* auxArr, uint8_t lgAuxArrInts, uint8_t lgConfigK, uint32_t slotNo) {
+ const uint32_t auxArrMask = (1 << lgAuxArrInts) - 1;
+ const uint32_t configKmask = (1 << lgConfigK) - 1;
+ uint32_t probe = slotNo & auxArrMask;
+ const uint32_t loopIndex = probe;
do {
- const int arrVal = auxArr[probe];
+ const uint32_t arrVal = auxArr[probe];
if (arrVal == HllUtil<A>::EMPTY) { //Compares on entire entry
return ~probe; //empty
}
else if (slotNo == (arrVal & configKmask)) { //Compares only on slotNo
return probe; //found given slotNo, return probe = index into aux array
}
- const int stride = (slotNo >> lgAuxArrInts) | 1;
+ const uint32_t stride = (slotNo >> lgAuxArrInts) | 1;
probe = (probe + stride) & auxArrMask;
} while (probe != loopIndex);
throw std::runtime_error("Key not found and no empty slots!");
@@ -263,12 +262,12 @@
template<typename A>
coupon_iterator<A> AuxHashMap<A>::begin(bool all) const {
- return coupon_iterator<A>(entries.data(), 1 << lgAuxArrInts, 0, all);
+ return coupon_iterator<A>(entries.data(), 1ULL << lgAuxArrInts, 0, all);
}
template<typename A>
coupon_iterator<A> AuxHashMap<A>::end() const {
- return coupon_iterator<A>(entries.data(), 1 << lgAuxArrInts, 1 << lgAuxArrInts, false);
+ return coupon_iterator<A>(entries.data(), 1ULL << lgAuxArrInts, 1ULL << lgAuxArrInts, false);
}
}
diff --git a/hll/include/AuxHashMap.hpp b/hll/include/AuxHashMap.hpp
index e18f15d..d4b155b 100644
--- a/hll/include/AuxHashMap.hpp
+++ b/hll/include/AuxHashMap.hpp
@@ -31,49 +31,49 @@
template<typename A>
class AuxHashMap final {
public:
- AuxHashMap(int lgAuxArrInts, int lgConfigK, const A& allocator);
- static AuxHashMap* newAuxHashMap(int lgAuxArrInts, int lgConfigK, const A& allocator);
+ AuxHashMap(uint8_t lgAuxArrInts, uint8_t lgConfigK, const A& allocator);
+ static AuxHashMap* newAuxHashMap(uint8_t lgAuxArrInts, uint8_t lgConfigK, const A& allocator);
static AuxHashMap* newAuxHashMap(const AuxHashMap<A>& that);
static AuxHashMap* deserialize(const void* bytes, size_t len,
- int lgConfigK,
- int auxCount, int lgAuxArrInts,
+ uint8_t lgConfigK,
+ uint32_t auxCount, uint8_t lgAuxArrInts,
bool srcCompact, const A& allocator);
- static AuxHashMap* deserialize(std::istream& is, int lgConfigK,
- int auxCount, int lgAuxArrInts,
+ static AuxHashMap* deserialize(std::istream& is, uint8_t lgConfigK,
+ uint32_t auxCount, uint8_t lgAuxArrInts,
bool srcCompact, const A& allocator);
virtual ~AuxHashMap() = default;
static std::function<void(AuxHashMap<A>*)> make_deleter();
AuxHashMap* copy() const;
- int getUpdatableSizeBytes() const;
- int getCompactSizeBytes() const;
+ uint32_t getUpdatableSizeBytes() const;
+ uint32_t getCompactSizeBytes() const;
- int getAuxCount() const;
- int* getAuxIntArr();
- int getLgAuxArrInts() const;
+ uint32_t getAuxCount() const;
+ uint32_t* getAuxIntArr();
+ uint8_t getLgAuxArrInts() const;
coupon_iterator<A> begin(bool all = false) const;
coupon_iterator<A> end() const;
- void mustAdd(int slotNo, int value);
- int mustFindValueFor(int slotNo) const;
- void mustReplace(int slotNo, int value);
+ void mustAdd(uint32_t slotNo, uint8_t value);
+ uint8_t mustFindValueFor(uint32_t slotNo) const;
+ void mustReplace(uint32_t slotNo, uint8_t value);
private:
typedef typename std::allocator_traits<A>::template rebind_alloc<AuxHashMap<A>> ahmAlloc;
- using vector_int = std::vector<int, typename std::allocator_traits<A>::template rebind_alloc<int>>;
+ using vector_int = std::vector<uint32_t, typename std::allocator_traits<A>::template rebind_alloc<uint32_t>>;
// static so it can be used when resizing
- static int find(const int* auxArr, int lgAuxArrInts, int lgConfigK, int slotNo);
+ static int32_t find(const uint32_t* auxArr, uint8_t lgAuxArrInts, uint8_t lgConfigK, uint32_t slotNo);
void checkGrow();
void growAuxSpace();
- const int lgConfigK;
- int lgAuxArrInts;
- int auxCount;
+ const uint8_t lgConfigK;
+ uint8_t lgAuxArrInts;
+ uint32_t auxCount;
vector_int entries;
};
diff --git a/hll/include/CompositeInterpolationXTable-internal.hpp b/hll/include/CompositeInterpolationXTable-internal.hpp
index 10aa047..347ea5c 100644
--- a/hll/include/CompositeInterpolationXTable-internal.hpp
+++ b/hll/include/CompositeInterpolationXTable-internal.hpp
@@ -27,16 +27,16 @@
namespace datasketches {
-static const int numXArrValues = 257;
+static const uint32_t numXArrValues = 257;
/**
* 18 Values, index 0 is LgK = 4, index 17 is LgK = 21.
*/
-static const int yStrides[] =
+static const uint32_t yStrides[] =
{1, 2, 3, 5, 10, 20, 40, 80, 160, 320, 640, 1280, 2560, 5120, 10240, 20480, 40960, 81920};
template<typename A>
-int CompositeInterpolationXTable<A>::get_y_stride(const int logK) {
+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: "
@@ -46,11 +46,11 @@
}
template<typename A>
-int CompositeInterpolationXTable<A>::get_x_arr_length() {
+uint32_t CompositeInterpolationXTable<A>::get_x_arr_length() {
return numXArrValues;
}
-static const double xArr[18][numXArrValues] = {
+static const double xArray[18][numXArrValues] = {
{
10.767999803534, 11.237701481774, 11.722738717438, 12.223246391222,
12.739366773787, 13.271184824495, 13.818759686650, 14.382159835785,
@@ -797,13 +797,13 @@
};
template<typename A>
-const double* CompositeInterpolationXTable<A>::get_x_arr(const int logK) {
+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: "
+ std::to_string(logK));
}
- return xArr[logK - HllUtil<A>::MIN_LOG_K];
+ return xArray[logK - HllUtil<A>::MIN_LOG_K];
}
}
diff --git a/hll/include/CompositeInterpolationXTable.hpp b/hll/include/CompositeInterpolationXTable.hpp
index 0fa0af8..4370115 100644
--- a/hll/include/CompositeInterpolationXTable.hpp
+++ b/hll/include/CompositeInterpolationXTable.hpp
@@ -27,10 +27,10 @@
template<typename A = std::allocator<uint8_t>>
class CompositeInterpolationXTable {
public:
- static int get_y_stride(int logK);
+ static uint32_t get_y_stride(uint8_t logK);
- static const double* get_x_arr(int logK);
- static int get_x_arr_length();
+ static const double* get_x_arr(uint8_t logK);
+ static uint32_t get_x_arr_length();
};
}
diff --git a/hll/include/CouponHashSet-internal.hpp b/hll/include/CouponHashSet-internal.hpp
index 67237db..5db9772 100644
--- a/hll/include/CouponHashSet-internal.hpp
+++ b/hll/include/CouponHashSet-internal.hpp
@@ -28,10 +28,10 @@
namespace datasketches {
template<typename A>
-static int find(const int* array, const int lgArrInts, const int coupon);
+static int32_t find(const uint32_t* array, uint8_t lgArrInts, uint32_t coupon);
template<typename A>
-CouponHashSet<A>::CouponHashSet(const int lgConfigK, const target_hll_type tgtHllType, const A& allocator)
+CouponHashSet<A>::CouponHashSet(uint8_t lgConfigK, target_hll_type tgtHllType, const A& allocator)
: CouponList<A>(lgConfigK, tgtHllType, hll_mode::SET, allocator)
{
if (lgConfigK <= 7) {
@@ -78,23 +78,23 @@
const target_hll_type tgtHllType = HllSketchImpl<A>::extractTgtHllType(data[HllUtil<A>::MODE_BYTE]);
- const int lgK = data[HllUtil<A>::LG_K_BYTE];
+ const uint8_t lgK = data[HllUtil<A>::LG_K_BYTE];
if (lgK <= 7) {
throw std::invalid_argument("Attempt to deserialize invalid CouponHashSet with lgConfigK <= 7. Found: "
+ std::to_string(lgK));
}
- int lgArrInts = data[HllUtil<A>::LG_ARR_BYTE];
+ uint8_t lgArrInts = data[HllUtil<A>::LG_ARR_BYTE];
const bool compactFlag = ((data[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::COMPACT_FLAG_MASK) ? true : false);
- int couponCount;
+ 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);
}
// Don't set couponCount in sketch here;
// we'll set later if updatable, and increment with updates if compact
- const int couponsInArray = (compactFlag ? couponCount : (1 << lgArrInts));
- const size_t expectedLength = HllUtil<A>::HASH_SET_INT_ARR_START + (couponsInArray * sizeof(int));
+ const uint32_t couponsInArray = (compactFlag ? couponCount : (1 << lgArrInts));
+ const size_t expectedLength = HllUtil<A>::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));
@@ -105,18 +105,18 @@
if (compactFlag) {
const uint8_t* curPos = data + HllUtil<A>::HASH_SET_INT_ARR_START;
- int coupon;
- for (int i = 0; i < couponCount; ++i, curPos += sizeof(coupon)) {
+ uint32_t coupon;
+ for (uint32_t i = 0; i < couponCount; ++i, curPos += sizeof(coupon)) {
std::memcpy(&coupon, curPos, sizeof(coupon));
sketch->couponUpdate(coupon);
}
} else {
- sketch->coupons.resize(1 << lgArrInts);
- sketch->couponCount = couponCount;
+ sketch->coupons_.resize(1ULL << lgArrInts);
+ sketch->couponCount_ = couponCount;
// only need to read valid coupons, unlike in stream case
- std::memcpy(sketch->coupons.data(),
+ std::memcpy(sketch->coupons_.data(),
data + HllUtil<A>::HASH_SET_INT_ARR_START,
- couponCount * sizeof(int));
+ couponCount * sizeof(uint32_t));
}
return sketch;
@@ -142,17 +142,17 @@
throw std::invalid_argument("Calling set constructor with non-set mode data");
}
- target_hll_type tgtHllType = HllSketchImpl<A>::extractTgtHllType(listHeader[HllUtil<A>::MODE_BYTE]);
+ const target_hll_type tgtHllType = HllSketchImpl<A>::extractTgtHllType(listHeader[HllUtil<A>::MODE_BYTE]);
- const int lgK = listHeader[HllUtil<A>::LG_K_BYTE];
+ const uint8_t lgK = listHeader[HllUtil<A>::LG_K_BYTE];
if (lgK <= 7) {
throw std::invalid_argument("Attempt to deserialize invalid CouponHashSet with lgConfigK <= 7. Found: "
+ std::to_string(lgK));
}
- int lgArrInts = listHeader[HllUtil<A>::LG_ARR_BYTE];
+ uint8_t lgArrInts = listHeader[HllUtil<A>::LG_ARR_BYTE];
const bool compactFlag = ((listHeader[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::COMPACT_FLAG_MASK) ? true : false);
- const auto couponCount = read<int>(is);
+ const auto couponCount = read<uint32_t>(is);
if (lgArrInts < HllUtil<A>::LG_INIT_SET_SIZE) {
lgArrInts = HllUtil<A>::computeLgArrInts(SET, couponCount, lgK);
}
@@ -165,15 +165,15 @@
// Don't set couponCount here;
// we'll set later if updatable, and increment with updates if compact
if (compactFlag) {
- for (int i = 0; i < couponCount; ++i) {
- const auto coupon = read<int>(is);
+ for (uint32_t i = 0; i < couponCount; ++i) {
+ const auto coupon = read<uint32_t>(is);
sketch->couponUpdate(coupon);
}
} else {
- sketch->coupons.resize(1 << lgArrInts);
- sketch->couponCount = couponCount;
+ sketch->coupons_.resize(1ULL << lgArrInts);
+ sketch->couponCount_ = couponCount;
// for stream processing, read entire list so read pointer ends up set correctly
- read(is, sketch->coupons.data(), sketch->coupons.size() * sizeof(int));
+ read(is, sketch->coupons_.data(), sketch->coupons_.size() * sizeof(uint32_t));
}
if (!is.good())
@@ -184,25 +184,25 @@
template<typename A>
CouponHashSet<A>* CouponHashSet<A>::copy() const {
- ChsAlloc chsa(this->coupons.get_allocator());
+ ChsAlloc chsa(this->coupons_.get_allocator());
return new (chsa.allocate(1)) CouponHashSet<A>(*this);
}
template<typename A>
-CouponHashSet<A>* CouponHashSet<A>::copyAs(const target_hll_type tgtHllType) const {
- ChsAlloc chsa(this->coupons.get_allocator());
+CouponHashSet<A>* CouponHashSet<A>::copyAs(target_hll_type tgtHllType) const {
+ ChsAlloc chsa(this->coupons_.get_allocator());
return new (chsa.allocate(1)) CouponHashSet<A>(*this, tgtHllType);
}
template<typename A>
-HllSketchImpl<A>* CouponHashSet<A>::couponUpdate(int coupon) {
- const uint8_t lgCouponArrInts = count_trailing_zeros_in_u32(this->coupons.size());
- const int index = find<A>(this->coupons.data(), lgCouponArrInts, coupon);
+HllSketchImpl<A>* CouponHashSet<A>::couponUpdate(uint32_t coupon) {
+ const uint8_t lgCouponArrInts = count_trailing_zeros_in_u32(static_cast<uint32_t>(this->coupons_.size()));
+ const int32_t index = find<A>(this->coupons_.data(), lgCouponArrInts, coupon);
if (index >= 0) {
return this; // found duplicate, ignore
}
- this->coupons[~index] = coupon; // found empty
- ++this->couponCount;
+ this->coupons_[~index] = coupon; // found empty
+ ++this->couponCount_;
if (checkGrowOrPromote()) {
return this->promoteHeapListOrSetToHll(*this);
}
@@ -210,20 +210,20 @@
}
template<typename A>
-int CouponHashSet<A>::getMemDataStart() const {
+uint32_t CouponHashSet<A>::getMemDataStart() const {
return HllUtil<A>::HASH_SET_INT_ARR_START;
}
template<typename A>
-int CouponHashSet<A>::getPreInts() const {
+uint8_t CouponHashSet<A>::getPreInts() const {
return HllUtil<A>::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())) {
- const uint8_t lgCouponArrInts = count_trailing_zeros_in_u32(this->coupons.size());
- if (lgCouponArrInts == (this->lgConfigK - 3)) { // at max size
+ if (static_cast<size_t>(HllUtil<A>::RESIZE_DENOM * this->couponCount_) > (HllUtil<A>::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
}
growHashSet(lgCouponArrInts + 1);
@@ -232,15 +232,15 @@
}
template<typename A>
-void CouponHashSet<A>::growHashSet(int tgtLgCoupArrSize) {
- const int tgtLen = 1 << tgtLgCoupArrSize;
- vector_int coupons_new(tgtLen, 0, this->coupons.get_allocator());
+void CouponHashSet<A>::growHashSet(uint8_t tgtLgCoupArrSize) {
+ const uint32_t tgtLen = 1 << tgtLgCoupArrSize;
+ vector_int coupons_new(tgtLen, 0, this->coupons_.get_allocator());
- const int srcLen = this->coupons.size();
- for (int i = 0; i < srcLen; ++i) { // scan existing array for non-zero values
- const int fetched = this->coupons[i];
+ 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) {
- const int idx = find<A>(coupons_new.data(), tgtLgCoupArrSize, fetched); // search TGT array
+ const int32_t idx = find<A>(coupons_new.data(), tgtLgCoupArrSize, fetched); // search TGT array
if (idx < 0) { // found EMPTY
coupons_new[~idx] = fetched; // insert
continue;
@@ -248,23 +248,23 @@
throw std::runtime_error("Error: Found duplicate coupon");
}
}
- this->coupons = std::move(coupons_new);
+ this->coupons_ = std::move(coupons_new);
}
template<typename A>
-static int find(const int* array, const int lgArrInts, const int coupon) {
- const int arrMask = (1 << lgArrInts) - 1;
- int probe = coupon & arrMask;
- const int loopIndex = probe;
+static int32_t find(const uint32_t* array, uint8_t lgArrInts, uint32_t coupon) {
+ const uint32_t arrMask = (1 << lgArrInts) - 1;
+ uint32_t probe = coupon & arrMask;
+ const uint32_t loopIndex = probe;
do {
- const int couponAtIdx = array[probe];
+ const uint32_t couponAtIdx = array[probe];
if (couponAtIdx == HllUtil<A>::EMPTY) {
return ~probe; //empty
}
else if (coupon == couponAtIdx) {
return probe; //duplicate
}
- const int stride = ((coupon & HllUtil<A>::KEY_MASK_26) >> lgArrInts) | 1;
+ const uint32_t stride = ((coupon & HllUtil<A>::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/CouponHashSet.hpp b/hll/include/CouponHashSet.hpp
index b9b99b7..fd22106 100644
--- a/hll/include/CouponHashSet.hpp
+++ b/hll/include/CouponHashSet.hpp
@@ -29,29 +29,29 @@
public:
static CouponHashSet* newSet(const void* bytes, size_t len, const A& allocator);
static CouponHashSet* newSet(std::istream& is, const A& allocator);
- CouponHashSet(int lgConfigK, target_hll_type tgtHllType, const A& allocator);
+ CouponHashSet(uint8_t lgConfigK, target_hll_type tgtHllType, const A& allocator);
CouponHashSet(const CouponHashSet& that, target_hll_type tgtHllType);
virtual ~CouponHashSet() = default;
virtual std::function<void(HllSketchImpl<A>*)> get_deleter() const;
protected:
- using vector_int = std::vector<int, typename std::allocator_traits<A>::template rebind_alloc<int>>;
+ using vector_int = std::vector<uint32_t, typename std::allocator_traits<A>::template rebind_alloc<uint32_t>>;
virtual CouponHashSet* copy() const;
virtual CouponHashSet* copyAs(target_hll_type tgtHllType) const;
- virtual HllSketchImpl<A>* couponUpdate(int coupon);
+ virtual HllSketchImpl<A>* couponUpdate(uint32_t coupon);
- virtual int getMemDataStart() const;
- virtual int getPreInts() const;
+ virtual uint32_t getMemDataStart() const;
+ virtual uint8_t getPreInts() const;
friend class HllSketchImplFactory<A>;
private:
using ChsAlloc = typename std::allocator_traits<A>::template rebind_alloc<CouponHashSet<A>>;
bool checkGrowOrPromote();
- void growHashSet(int tgtLgCoupArrSize);
+ void growHashSet(uint8_t tgtLgCoupArrSize);
};
}
diff --git a/hll/include/CouponList-internal.hpp b/hll/include/CouponList-internal.hpp
index c48c7c2..1cd9403 100644
--- a/hll/include/CouponList-internal.hpp
+++ b/hll/include/CouponList-internal.hpp
@@ -31,19 +31,19 @@
namespace datasketches {
template<typename A>
-CouponList<A>::CouponList(const int lgConfigK, const target_hll_type tgtHllType, const hll_mode mode, const A& allocator):
+CouponList<A>::CouponList(uint8_t lgConfigK, target_hll_type tgtHllType, hll_mode mode, const A& allocator):
HllSketchImpl<A>(lgConfigK, tgtHllType, mode, false),
-couponCount(0),
-oooFlag(false),
-coupons(1 << (mode == hll_mode::LIST ? HllUtil<A>::LG_INIT_LIST_SIZE : HllUtil<A>::LG_INIT_SET_SIZE), 0, allocator)
+couponCount_(0),
+oooFlag_(false),
+coupons_(1ULL << (mode_ == hll_mode::LIST ? HllUtil<A>::LG_INIT_LIST_SIZE : HllUtil<A>::LG_INIT_SET_SIZE), 0, allocator)
{}
template<typename A>
CouponList<A>::CouponList(const CouponList& that, const target_hll_type tgtHllType):
-HllSketchImpl<A>(that.lgConfigK, tgtHllType, that.mode, false),
-couponCount(that.couponCount),
-oooFlag(that.oooFlag),
-coupons(that.coupons)
+HllSketchImpl<A>(that.lgConfigK_, tgtHllType, that.mode_, false),
+couponCount_(that.couponCount_),
+oooFlag_(that.oooFlag_),
+coupons_(that.coupons_)
{}
template<typename A>
@@ -58,13 +58,13 @@
template<typename A>
CouponList<A>* CouponList<A>::copy() const {
- ClAlloc cla(coupons.get_allocator());
+ ClAlloc cla(coupons_.get_allocator());
return new (cla.allocate(1)) CouponList<A>(*this);
}
template<typename A>
CouponList<A>* CouponList<A>::copyAs(target_hll_type tgtHllType) const {
- ClAlloc cla(coupons.get_allocator());
+ ClAlloc cla(coupons_.get_allocator());
return new (cla.allocate(1)) CouponList<A>(*this, tgtHllType);
}
@@ -92,14 +92,14 @@
target_hll_type tgtHllType = HllSketchImpl<A>::extractTgtHllType(data[HllUtil<A>::MODE_BYTE]);
- const int lgK = data[HllUtil<A>::LG_K_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 int couponCount = data[HllUtil<A>::LIST_COUNT_BYTE];
- const int couponsInArray = (compact ? couponCount : (1 << HllUtil<A>::computeLgArrInts(LIST, couponCount, lgK)));
- const size_t expectedLength = HllUtil<A>::LIST_INT_ARR_START + (couponsInArray * sizeof(int));
+ const uint32_t couponCount = data[HllUtil<A>::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));
if (len < expectedLength) {
throw std::out_of_range("Byte array too short for sketch. Expected " + std::to_string(expectedLength)
+ ", found: " + std::to_string(len));
@@ -107,12 +107,12 @@
ClAlloc cla(allocator);
CouponList<A>* sketch = new (cla.allocate(1)) CouponList<A>(lgK, tgtHllType, mode, allocator);
- sketch->couponCount = couponCount;
+ sketch->couponCount_ = couponCount;
sketch->putOutOfOrderFlag(oooFlag); // should always be false for LIST
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(int));
+ std::memcpy(sketch->coupons_.data(), data + HllUtil<A>::LIST_INT_ARR_START, couponCount * sizeof(uint32_t));
}
return sketch;
@@ -140,7 +140,7 @@
const target_hll_type tgtHllType = HllSketchImpl<A>::extractTgtHllType(listHeader[HllUtil<A>::MODE_BYTE]);
- const int lgK = (int) listHeader[HllUtil<A>::LG_K_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);
@@ -149,16 +149,16 @@
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 int couponCount = listHeader[HllUtil<A>::LIST_COUNT_BYTE];
- sketch->couponCount = couponCount;
+ const uint32_t couponCount = listHeader[HllUtil<A>::LIST_COUNT_BYTE];
+ sketch->couponCount_ = couponCount;
sketch->putOutOfOrderFlag(oooFlag); // should always be false for LIST
if (!emptyFlag) {
// For stream processing, need to read entire number written to stream so read
// pointer ends up set correctly.
// If not compact, still need to read empty items even though in order.
- const int numToRead = (compact ? couponCount : sketch->coupons.size());
- read(is, sketch->coupons.data(), numToRead * sizeof(int));
+ const uint32_t numToRead = (compact ? couponCount : static_cast<uint32_t>(sketch->coupons_.size()));
+ read(is, sketch->coupons_.data(), numToRead * sizeof(uint32_t));
}
if (!is.good())
@@ -176,14 +176,14 @@
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(coupons.size());
+ 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>::LIST_COUNT_BYTE] = static_cast<uint8_t>(this->mode_ == LIST ? couponCount_ : 0);
bytes[HllUtil<A>::MODE_BYTE] = this->makeModeByte();
- if (this->mode == SET) {
- std::memcpy(bytes + HllUtil<A>::HASH_SET_COUNT_INT, &couponCount, sizeof(couponCount));
+ if (this->mode_ == SET) {
+ std::memcpy(bytes + HllUtil<A>::HASH_SET_COUNT_INT, &couponCount_, sizeof(couponCount_));
}
// coupons
@@ -191,12 +191,12 @@
const int sw = (isCompact() ? 2 : 0) | (compact ? 1 : 0);
switch (sw) {
case 0: { // src updatable, dst updatable
- std::memcpy(bytes + getMemDataStart(), coupons.data(), coupons.size() * sizeof(int));
+ std::memcpy(bytes + getMemDataStart(), coupons_.data(), coupons_.size() * sizeof(uint32_t));
break;
}
case 1: { // src updatable, dst compact
bytes += getMemDataStart(); // reusing pointer for incremental writes
- for (uint32_t coupon: *this) {
+ for (const uint32_t coupon: *this) {
std::memcpy(bytes, &coupon, sizeof(coupon));
bytes += sizeof(coupon);
}
@@ -213,33 +213,33 @@
template<typename A>
void CouponList<A>::serialize(std::ostream& os, const bool compact) const {
// header
- const uint8_t preInts(getPreInts());
+ const uint8_t preInts = getPreInts();
write(os, preInts);
const uint8_t serialVersion(HllUtil<A>::SER_VER);
write(os, serialVersion);
const uint8_t familyId(HllUtil<A>::FAMILY_ID);
write(os, familyId);
- const uint8_t lgKByte((uint8_t) this->lgConfigK);
+ const uint8_t lgKByte = this->lgConfigK_;
write(os, lgKByte);
- const uint8_t lgArrIntsByte(count_trailing_zeros_in_u32(coupons.size()));
+ const uint8_t lgArrIntsByte = count_trailing_zeros_in_u32(static_cast<uint32_t>(coupons_.size()));
write(os, lgArrIntsByte);
- const uint8_t flagsByte(this->makeFlagsByte(compact));
+ const uint8_t flagsByte = this->makeFlagsByte(compact);
write(os, flagsByte);
- if (this->mode == LIST) {
- const uint8_t listCount((uint8_t) couponCount);
+ if (this->mode_ == LIST) {
+ const uint8_t listCount = static_cast<uint8_t>(couponCount_);
write(os, listCount);
} else { // mode == SET
- const uint8_t unused(0);
+ const uint8_t unused = 0;
write(os, unused);
}
- const uint8_t modeByte(this->makeModeByte());
+ const uint8_t modeByte = this->makeModeByte();
write(os, modeByte);
- if (this->mode == SET) {
+ if (this->mode_ == SET) {
// writing as int, already stored as int
- write(os, couponCount);
+ write(os, couponCount_);
}
// coupons
@@ -247,11 +247,11 @@
const int sw = (isCompact() ? 2 : 0) | (compact ? 1 : 0);
switch (sw) {
case 0: { // src updatable, dst updatable
- write(os, coupons.data(), coupons.size() * sizeof(int));
+ write(os, coupons_.data(), coupons_.size() * sizeof(uint32_t));
break;
}
case 1: { // src updatable, dst compact
- for (uint32_t coupon: *this) {
+ for (const uint32_t coupon: *this) {
write(os, coupon);
}
break;
@@ -265,14 +265,14 @@
}
template<typename A>
-HllSketchImpl<A>* CouponList<A>::couponUpdate(int coupon) {
- for (size_t i = 0; i < coupons.size(); ++i) { // search for empty slot
- const int couponAtIdx = coupons[i];
+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) {
- coupons[i] = coupon; // the actual update
- ++couponCount;
- if (couponCount == static_cast<int>(coupons.size())) { // array full
- if (this->lgConfigK < 8) {
+ coupons_[i] = coupon; // the actual update
+ ++couponCount_;
+ if (couponCount_ == static_cast<int>(coupons_.size())) { // array full
+ if (this->lgConfigK_ < 8) {
return promoteHeapListOrSetToHll(*this);
}
return promoteHeapListToSet(*this);
@@ -293,54 +293,51 @@
template<typename A>
double CouponList<A>::getEstimate() const {
- const int couponCount = getCouponCount();
- const double est = CubicInterpolation<A>::usingXAndYTables(couponCount);
- return fmax(est, couponCount);
+ const double est = CubicInterpolation<A>::usingXAndYTables(couponCount_);
+ return fmax(est, couponCount_);
}
template<typename A>
-double CouponList<A>::getLowerBound(const int numStdDev) const {
+double CouponList<A>::getLowerBound(uint8_t numStdDev) const {
HllUtil<A>::checkNumStdDev(numStdDev);
- const int couponCount = getCouponCount();
- const double est = CubicInterpolation<A>::usingXAndYTables(couponCount);
+ const double est = CubicInterpolation<A>::usingXAndYTables(couponCount_);
const double tmp = est / (1.0 + (numStdDev * HllUtil<A>::COUPON_RSE));
- return fmax(tmp, couponCount);
+ return fmax(tmp, couponCount_);
}
template<typename A>
-double CouponList<A>::getUpperBound(const int numStdDev) const {
+double CouponList<A>::getUpperBound(uint8_t numStdDev) const {
HllUtil<A>::checkNumStdDev(numStdDev);
- const int couponCount = getCouponCount();
- const double est = CubicInterpolation<A>::usingXAndYTables(couponCount);
+ const double est = CubicInterpolation<A>::usingXAndYTables(couponCount_);
const double tmp = est / (1.0 - (numStdDev * HllUtil<A>::COUPON_RSE));
- return fmax(tmp, couponCount);
+ return fmax(tmp, couponCount_);
}
template<typename A>
bool CouponList<A>::isEmpty() const { return getCouponCount() == 0; }
template<typename A>
-int CouponList<A>::getUpdatableSerializationBytes() const {
- return getMemDataStart() + coupons.size() * sizeof(int);
+uint32_t CouponList<A>::getUpdatableSerializationBytes() const {
+ return getMemDataStart() + static_cast<uint32_t>(coupons_.size()) * sizeof(uint32_t);
}
template<typename A>
-int CouponList<A>::getCouponCount() const {
- return couponCount;
+uint32_t CouponList<A>::getCouponCount() const {
+ return couponCount_;
}
template<typename A>
-int CouponList<A>::getCompactSerializationBytes() const {
- return getMemDataStart() + (couponCount << 2);
+uint32_t CouponList<A>::getCompactSerializationBytes() const {
+ return getMemDataStart() + (couponCount_ << 2);
}
template<typename A>
-int CouponList<A>::getMemDataStart() const {
+uint32_t CouponList<A>::getMemDataStart() const {
return HllUtil<A>::LIST_INT_ARR_START;
}
template<typename A>
-int CouponList<A>::getPreInts() const {
+uint8_t CouponList<A>::getPreInts() const {
return HllUtil<A>::LIST_PREINTS;
}
@@ -348,16 +345,16 @@
bool CouponList<A>::isCompact() const { return false; }
template<typename A>
-bool CouponList<A>::isOutOfOrderFlag() const { return oooFlag; }
+bool CouponList<A>::isOutOfOrderFlag() const { return oooFlag_; }
template<typename A>
void CouponList<A>::putOutOfOrderFlag(bool oooFlag) {
- this->oooFlag = oooFlag;
+ oooFlag_ = oooFlag;
}
template<typename A>
A CouponList<A>::getAllocator() const {
- return coupons.get_allocator();
+ return coupons_.get_allocator();
}
template<typename A>
@@ -372,12 +369,12 @@
template<typename A>
coupon_iterator<A> CouponList<A>::begin(bool all) const {
- return coupon_iterator<A>(coupons.data(), coupons.size(), 0, all);
+ return coupon_iterator<A>(coupons_.data(), coupons_.size(), 0, all);
}
template<typename A>
coupon_iterator<A> CouponList<A>::end() const {
- return coupon_iterator<A>(coupons.data(), coupons.size(), coupons.size(), false);
+ return coupon_iterator<A>(coupons_.data(), coupons_.size(), coupons_.size(), false);
}
}
diff --git a/hll/include/CouponList.hpp b/hll/include/CouponList.hpp
index c19569e..cf0a662 100644
--- a/hll/include/CouponList.hpp
+++ b/hll/include/CouponList.hpp
@@ -33,7 +33,7 @@
template<typename A>
class CouponList : public HllSketchImpl<A> {
public:
- CouponList(int lgConfigK, target_hll_type tgtHllType, hll_mode mode, const A& allocator);
+ CouponList(uint8_t lgConfigK, target_hll_type tgtHllType, hll_mode mode, const A& allocator);
CouponList(const CouponList& that, target_hll_type tgtHllType);
static CouponList* newList(const void* bytes, size_t len, const A& allocator);
@@ -47,15 +47,15 @@
virtual CouponList* copy() const;
virtual CouponList* copyAs(target_hll_type tgtHllType) const;
- virtual HllSketchImpl<A>* couponUpdate(int coupon);
+ virtual HllSketchImpl<A>* couponUpdate(uint32_t coupon);
virtual double getEstimate() const;
virtual double getCompositeEstimate() const;
- virtual double getUpperBound(int numStdDev) const;
- virtual double getLowerBound(int numStdDev) const;
+ virtual double getUpperBound(uint8_t numStdDev) const;
+ virtual double getLowerBound(uint8_t numStdDev) const;
virtual bool isEmpty() const;
- virtual int getCouponCount() const;
+ virtual uint32_t getCouponCount() const;
coupon_iterator<A> begin(bool all = false) const;
coupon_iterator<A> end() const;
@@ -63,24 +63,24 @@
protected:
using ClAlloc = typename std::allocator_traits<A>::template rebind_alloc<CouponList<A>>;
- using vector_int = std::vector<int, typename std::allocator_traits<A>::template rebind_alloc<int>>;
+ using vector_int = std::vector<uint32_t, typename std::allocator_traits<A>::template rebind_alloc<uint32_t>>;
HllSketchImpl<A>* promoteHeapListToSet(CouponList& list);
HllSketchImpl<A>* promoteHeapListOrSetToHll(CouponList& src);
- virtual int getUpdatableSerializationBytes() const;
- virtual int getCompactSerializationBytes() const;
- virtual int getMemDataStart() const;
- virtual int getPreInts() const;
+ virtual uint32_t getUpdatableSerializationBytes() const;
+ virtual uint32_t getCompactSerializationBytes() const;
+ virtual uint32_t getMemDataStart() const;
+ virtual uint8_t getPreInts() const;
virtual bool isCompact() const;
virtual bool isOutOfOrderFlag() const;
virtual void putOutOfOrderFlag(bool oooFlag);
virtual A getAllocator() const;
- int couponCount;
- bool oooFlag;
- vector_int coupons;
+ uint32_t couponCount_;
+ bool oooFlag_;
+ vector_int coupons_;
friend class HllSketchImplFactory<A>;
};
diff --git a/hll/include/CubicInterpolation-internal.hpp b/hll/include/CubicInterpolation-internal.hpp
index be03e80..c60ddab 100644
--- a/hll/include/CubicInterpolation-internal.hpp
+++ b/hll/include/CubicInterpolation-internal.hpp
@@ -102,10 +102,8 @@
else if (offset == numEntries-2) { // corner case
return (interpolateUsingXAndYTables<A>(xArr, yArr, (offset-2), x));
}
- else { // main case
- return (interpolateUsingXAndYTables<A>(xArr, yArr, (offset-1), x));
- }
- throw std::logic_error("Exception should be unreachable");
+ // main case
+ return (interpolateUsingXAndYTables<A>(xArr, yArr, (offset-1), x));
}
// In C: again-two-registers cubic_interpolate_aux L1368
diff --git a/hll/include/HarmonicNumbers-internal.hpp b/hll/include/HarmonicNumbers-internal.hpp
index db73b86..4ac1e72 100644
--- a/hll/include/HarmonicNumbers-internal.hpp
+++ b/hll/include/HarmonicNumbers-internal.hpp
@@ -68,7 +68,7 @@
if (x_i < NUM_EXACT_HARMONIC_NUMBERS) {
return tableOfExactHarmonicNumbers[x_i];
} else {
- double x = x_i;
+ double x = static_cast<double>(x_i);
double invSq = 1.0 / (x * x);
double sum = log(x) + EULER_MASCHERONI_CONSTANT + (1.0 / (2.0 * x));
/* note: the number of terms included from this series expansion is appropriate
diff --git a/hll/include/Hll4Array-internal.hpp b/hll/include/Hll4Array-internal.hpp
index f93014a..070aae0 100644
--- a/hll/include/Hll4Array-internal.hpp
+++ b/hll/include/Hll4Array-internal.hpp
@@ -30,12 +30,12 @@
namespace datasketches {
template<typename A>
-Hll4Array<A>::Hll4Array(const int lgConfigK, const bool startFullSize, const A& allocator):
+Hll4Array<A>::Hll4Array(uint8_t lgConfigK, bool startFullSize, const A& allocator):
HllArray<A>(lgConfigK, target_hll_type::HLL_4, startFullSize, allocator),
-auxHashMap(nullptr)
+auxHashMap_(nullptr)
{
- const int numBytes = this->hll4ArrBytes(lgConfigK);
- this->hllByteArr.resize(numBytes, 0);
+ const uint32_t numBytes = this->hll4ArrBytes(lgConfigK);
+ this->hllByteArr_.resize(numBytes, 0);
}
template<typename A>
@@ -44,18 +44,18 @@
{
// can determine hllByteArr size in parent class, no need to allocate here
// but parent class doesn't handle the auxHashMap
- if (that.auxHashMap != nullptr) {
- auxHashMap = that.auxHashMap->copy();
+ if (that.auxHashMap_ != nullptr) {
+ auxHashMap_ = that.auxHashMap_->copy();
} else {
- auxHashMap = nullptr;
+ auxHashMap_ = nullptr;
}
}
template<typename A>
Hll4Array<A>::~Hll4Array() {
// hllByteArr deleted in parent
- if (auxHashMap != nullptr) {
- AuxHashMap<A>::make_deleter()(auxHashMap);
+ if (auxHashMap_ != nullptr) {
+ AuxHashMap<A>::make_deleter()(auxHashMap_);
}
}
@@ -78,11 +78,11 @@
}
template<typename A>
-int Hll4Array<A>::getUpdatableSerializationBytes() const {
+uint32_t Hll4Array<A>::getUpdatableSerializationBytes() const {
AuxHashMap<A>* auxHashMap = getAuxHashMap();
- int auxBytes;
+ uint32_t auxBytes;
if (auxHashMap == nullptr) {
- auxBytes = 4 << HllUtil<A>::LG_AUX_ARR_INTS[this->lgConfigK];
+ auxBytes = 4 << HllUtil<A>::LG_AUX_ARR_INTS[this->lgConfigK_];
} else {
auxBytes = 4 << auxHashMap->getLgAuxArrInts();
}
@@ -90,23 +90,23 @@
}
template<typename A>
-int Hll4Array<A>::getHllByteArrBytes() const {
- return this->hll4ArrBytes(this->lgConfigK);
+uint32_t Hll4Array<A>::getHllByteArrBytes() const {
+ return this->hll4ArrBytes(this->lgConfigK_);
}
template<typename A>
AuxHashMap<A>* Hll4Array<A>::getAuxHashMap() const {
- return auxHashMap;
+ return auxHashMap_;
}
template<typename A>
void Hll4Array<A>::putAuxHashMap(AuxHashMap<A>* auxHashMap) {
- this->auxHashMap = auxHashMap;
+ this->auxHashMap_ = auxHashMap;
}
template<typename A>
-uint8_t Hll4Array<A>::getSlot(int slotNo) const {
- const uint8_t byte = this->hllByteArr[slotNo >> 1];
+uint8_t Hll4Array<A>::getSlot(uint32_t slotNo) const {
+ const uint8_t byte = this->hllByteArr_[slotNo >> 1];
if ((slotNo & 1) > 0) { // odd?
return byte >> 4;
}
@@ -116,53 +116,53 @@
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;
- return auxHashMap->mustFindValueFor(index);
+ if (value != HllUtil<A>::AUX_TOKEN) return value + this->curMin_;
+ return auxHashMap_->mustFindValueFor(index);
}
template<typename A>
-HllSketchImpl<A>* Hll4Array<A>::couponUpdate(const int coupon) {
+HllSketchImpl<A>* Hll4Array<A>::couponUpdate(uint32_t coupon) {
internalCouponUpdate(coupon);
return this;
}
template<typename A>
-void Hll4Array<A>::internalCouponUpdate(const int coupon) {
- const int newValue = HllUtil<A>::getValue(coupon);
- if (newValue <= this->curMin) {
+void Hll4Array<A>::internalCouponUpdate(uint32_t coupon) {
+ const uint8_t newValue = HllUtil<A>::getValue(coupon);
+ if (newValue <= this->curMin_) {
return; // quick rejection, but only works for large N
}
- const int configKmask = (1 << this->lgConfigK) - 1;
- const int slotNo = HllUtil<A>::getLow26(coupon) & configKmask;
+ const uint32_t configKmask = (1 << this->lgConfigK_) - 1;
+ const uint32_t slotNo = HllUtil<A>::getLow26(coupon) & configKmask;
internalHll4Update(slotNo, newValue);
}
template<typename A>
-void Hll4Array<A>::putSlot(int slotNo, uint8_t newValue) {
- const int byteno = slotNo >> 1;
- const uint8_t oldValue = this->hllByteArr[byteno];
+void Hll4Array<A>::putSlot(uint32_t slotNo, uint8_t newValue) {
+ const uint32_t byteno = slotNo >> 1;
+ const uint8_t oldValue = this->hllByteArr_[byteno];
if ((slotNo & 1) == 0) { // set low nibble
- this->hllByteArr[byteno]
+ this->hllByteArr_[byteno]
= ((oldValue & HllUtil<A>::hiNibbleMask) | (newValue & HllUtil<A>::loNibbleMask));
} else { // set high nibble
- this->hllByteArr[byteno]
+ this->hllByteArr_[byteno]
= ((oldValue & HllUtil<A>::loNibbleMask) | ((newValue << 4) & HllUtil<A>::hiNibbleMask));
}
}
//In C: two-registers.c Line 836 in "hhb_abstract_set_slot_if_new_value_bigger" non-sparse
template<typename A>
-void Hll4Array<A>::internalHll4Update(const int slotNo, const int newVal) {
+void Hll4Array<A>::internalHll4Update(uint32_t slotNo, uint8_t newVal) {
- const int rawStoredOldValue = getSlot(slotNo); // could be a 0
+ const uint8_t rawStoredOldValue = getSlot(slotNo); // could be a 0
// this is provably a LB:
- const int lbOnOldValue = rawStoredOldValue + this->curMin; // lower bound, could be 0
+ const uint8_t lbOnOldValue = rawStoredOldValue + this->curMin_; // lower bound, could be 0
if (newVal > lbOnOldValue) { // 842
// Note: if an AUX_TOKEN exists, then auxHashMap must already exist
// 846: rawStoredOldValue == AUX_TOKEN
- const int actualOldValue = (rawStoredOldValue < HllUtil<A>::AUX_TOKEN)
- ? (lbOnOldValue) : (auxHashMap->mustFindValueFor(slotNo));
+ const uint8_t actualOldValue = (rawStoredOldValue < HllUtil<A>::AUX_TOKEN)
+ ? (lbOnOldValue) : (auxHashMap_->mustFindValueFor(slotNo));
if (newVal > actualOldValue) { // 848: actualOldValue could still be 0; newValue > 0
// we know that the array will change, but we haven't actually updated yet
@@ -170,7 +170,7 @@
// newVal >= curMin
- const int shiftedNewValue = newVal - this->curMin; // 874
+ const uint8_t shiftedNewValue = newVal - this->curMin_; // 874
// redundant since we know newVal >= curMin,
// and lgConfigK bounds do not allow overflowing an int
//assert(shiftedNewValue >= 0);
@@ -183,7 +183,7 @@
// 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
- auxHashMap->mustReplace(slotNo, newVal);
+ auxHashMap_->mustReplace(slotNo, newVal);
}
else { // case 2: 885
// This is the hypothetical case where the old value is an exception and the new one is not,
@@ -195,10 +195,11 @@
// 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);
- if (auxHashMap == nullptr) {
- auxHashMap = AuxHashMap<A>::newAuxHashMap(HllUtil<A>::LG_AUX_ARR_INTS[this->lgConfigK], this->lgConfigK, this->getAllocator());
+ if (auxHashMap_ == nullptr) {
+ auxHashMap_ = AuxHashMap<A>::newAuxHashMap(HllUtil<A>::LG_AUX_ARR_INTS[this->lgConfigK_],
+ this->lgConfigK_, this->getAllocator());
}
- auxHashMap->mustAdd(slotNo, newVal);
+ auxHashMap_->mustAdd(slotNo, newVal);
}
else { // case 4: 897
// This is the case where neither the old value nor the new value is an exception.
@@ -208,9 +209,9 @@
}
// we just increased a pair value, so it might be time to change curMin
- if (actualOldValue == this->curMin) { // 908
+ if (actualOldValue == this->curMin_) { // 908
this->decNumAtCurMin();
- while (this->numAtCurMin == 0) {
+ while (this->numAtCurMin_ == 0) {
shiftToBiggerCurMin(); // increases curMin by 1, builds a new aux table
// shifts values in 4-bit table and recounts curMin
}
@@ -227,20 +228,20 @@
// In C: again-two-registers.c Lines 710 "hhb_shift_to_bigger_curmin"
template<typename A>
void Hll4Array<A>::shiftToBiggerCurMin() {
- const int newCurMin = this->curMin + 1;
- const int configK = 1 << this->lgConfigK;
- const int configKmask = configK - 1;
+ const uint8_t newCurMin = this->curMin_ + 1;
+ const uint32_t configK = 1 << this->lgConfigK_;
+ const uint32_t configKmask = configK - 1;
- int numAtNewCurMin = 0;
- int numAuxTokens = 0;
+ uint32_t numAtNewCurMin = 0;
+ uint32_t numAuxTokens = 0;
// Walk through the slots of 4-bit array decrementing stored values by one unless it
// equals AUX_TOKEN, where it is left alone but counted to be checked later.
// If oldStoredValue is 0 it is an error.
// If the decremented value is 0, we increment numAtNewCurMin.
// Because getNibble is masked to 4 bits oldStoredValue can never be > 15 or negative
- for (int i = 0; i < configK; i++) { //724
- int oldStoredValue = getSlot(i);
+ for (uint32_t i = 0; i < configK; i++) { //724
+ uint8_t oldStoredValue = getSlot(i);
if (oldStoredValue == 0) {
throw std::runtime_error("Array slots cannot be 0 at this point.");
}
@@ -249,7 +250,7 @@
if (oldStoredValue == 0) { numAtNewCurMin++; }
} else { //oldStoredValue == AUX_TOKEN
numAuxTokens++;
- if (auxHashMap == nullptr) {
+ if (auxHashMap_ == nullptr) {
throw std::logic_error("auxHashMap cannot be null at this point");
}
}
@@ -258,12 +259,12 @@
// If old AuxHashMap exists, walk through it updating some slots and build a new AuxHashMap
// if needed.
AuxHashMap<A>* newAuxMap = nullptr;
- if (auxHashMap != nullptr) {
- int slotNum;
- int oldActualVal;
- int newShiftedVal;
+ if (auxHashMap_ != nullptr) {
+ uint32_t slotNum;
+ uint8_t oldActualVal;
+ uint8_t newShiftedVal;
- for (auto coupon: *auxHashMap) {
+ for (const auto coupon: *auxHashMap_) {
slotNum = HllUtil<A>::getLow26(coupon) & configKmask;
oldActualVal = HllUtil<A>::getValue(coupon);
newShiftedVal = oldActualVal - newCurMin;
@@ -286,7 +287,8 @@
} 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], this->lgConfigK, this->getAllocator());
+ newAuxMap = AuxHashMap<A>::newAuxHashMap(HllUtil<A>::LG_AUX_ARR_INTS[this->lgConfigK_],
+ this->lgConfigK_, this->getAllocator());
}
newAuxMap->mustAdd(slotNum, oldActualVal);
}
@@ -305,28 +307,30 @@
}
}
- if (auxHashMap != nullptr) {
- AuxHashMap<A>::make_deleter()(auxHashMap);
+ if (auxHashMap_ != nullptr) {
+ AuxHashMap<A>::make_deleter()(auxHashMap_);
}
- auxHashMap = newAuxMap;
+ auxHashMap_ = newAuxMap;
- this->curMin = newCurMin;
- this->numAtCurMin = numAtNewCurMin;
+ this->curMin_ = newCurMin;
+ this->numAtCurMin_ = numAtNewCurMin;
}
template<typename A>
typename HllArray<A>::const_iterator Hll4Array<A>::begin(bool all) const {
- return typename HllArray<A>::const_iterator(this->hllByteArr.data(), 1 << this->lgConfigK, 0, this->tgtHllType, auxHashMap, this->curMin, all);
+ return typename HllArray<A>::const_iterator(this->hllByteArr_.data(), 1 << this->lgConfigK_, 0, this->tgtHllType_,
+ auxHashMap_, this->curMin_, all);
}
template<typename A>
typename HllArray<A>::const_iterator Hll4Array<A>::end() const {
- return typename HllArray<A>::const_iterator(this->hllByteArr.data(), 1 << this->lgConfigK, 1 << this->lgConfigK, this->tgtHllType, auxHashMap, this->curMin, false);
+ return typename HllArray<A>::const_iterator(this->hllByteArr_.data(), 1 << this->lgConfigK_, 1 << this->lgConfigK_,
+ this->tgtHllType_, auxHashMap_, this->curMin_, false);
}
template<typename A>
void Hll4Array<A>::mergeHll(const HllArray<A>& src) {
- for (auto coupon: src) {
+ for (const auto coupon: src) {
internalCouponUpdate(coupon);
}
}
diff --git a/hll/include/Hll4Array.hpp b/hll/include/Hll4Array.hpp
index 38b2c94..4542dec 100644
--- a/hll/include/Hll4Array.hpp
+++ b/hll/include/Hll4Array.hpp
@@ -31,7 +31,7 @@
template<typename A>
class Hll4Array final : public HllArray<A> {
public:
- explicit Hll4Array(int lgConfigK, bool startFullSize, const A& allocator);
+ explicit Hll4Array(uint8_t lgConfigK, bool startFullSize, const A& allocator);
explicit Hll4Array(const Hll4Array<A>& that);
virtual ~Hll4Array();
@@ -39,14 +39,14 @@
virtual Hll4Array* copy() const;
- inline uint8_t getSlot(int slotNo) const;
- inline void putSlot(int slotNo, uint8_t value);
+ inline uint8_t getSlot(uint32_t slotNo) const;
+ inline void putSlot(uint32_t slotNo, uint8_t value);
inline uint8_t get_value(uint32_t index) const;
- virtual int getUpdatableSerializationBytes() const;
- virtual int getHllByteArrBytes() const;
+ virtual uint32_t getUpdatableSerializationBytes() const;
+ virtual uint32_t getHllByteArrBytes() const;
- virtual HllSketchImpl<A>* couponUpdate(int coupon) final;
+ virtual HllSketchImpl<A>* couponUpdate(uint32_t coupon) final;
void mergeHll(const HllArray<A>& src);
virtual AuxHashMap<A>* getAuxHashMap() const;
@@ -57,11 +57,11 @@
virtual typename HllArray<A>::const_iterator end() const;
private:
- void internalCouponUpdate(int coupon);
- void internalHll4Update(int slotNo, int newVal);
+ void internalCouponUpdate(uint32_t coupon);
+ void internalHll4Update(uint32_t slotNo, uint8_t newVal);
void shiftToBiggerCurMin();
- AuxHashMap<A>* auxHashMap;
+ AuxHashMap<A>* auxHashMap_;
};
}
diff --git a/hll/include/Hll6Array-internal.hpp b/hll/include/Hll6Array-internal.hpp
index e9f6e9f..2d7ae9a 100644
--- a/hll/include/Hll6Array-internal.hpp
+++ b/hll/include/Hll6Array-internal.hpp
@@ -27,11 +27,11 @@
namespace datasketches {
template<typename A>
-Hll6Array<A>::Hll6Array(const int lgConfigK, const bool startFullSize, const A& allocator):
+Hll6Array<A>::Hll6Array(uint8_t lgConfigK, bool startFullSize, const A& allocator):
HllArray<A>(lgConfigK, target_hll_type::HLL_6, startFullSize, allocator)
{
const int numBytes = this->hll6ArrBytes(lgConfigK);
- this->hllByteArr.resize(numBytes, 0);
+ this->hllByteArr_.resize(numBytes, 0);
}
template<typename A>
@@ -53,57 +53,57 @@
}
template<typename A>
-uint8_t Hll6Array<A>::getSlot(int slotNo) const {
- const int startBit = slotNo * 6;
- const int shift = startBit & 0x7;
- const int byteIdx = startBit >> 3;
- const uint16_t twoByteVal = (this->hllByteArr[byteIdx + 1] << 8) | this->hllByteArr[byteIdx];
+uint8_t Hll6Array<A>::getSlot(uint32_t slotNo) const {
+ const uint32_t startBit = slotNo * 6;
+ 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;
}
template<typename A>
-void Hll6Array<A>::putSlot(int slotNo, uint8_t value) {
- const int startBit = slotNo * 6;
- const int shift = startBit & 0x7;
- const int byteIdx = startBit >> 3;
+void Hll6Array<A>::putSlot(uint32_t slotNo, uint8_t value) {
+ const uint32_t startBit = slotNo * 6;
+ const uint32_t shift = startBit & 0x7;
+ const uint32_t byteIdx = startBit >> 3;
const uint16_t valShifted = (value & 0x3F) << shift;
- uint16_t curMasked = (this->hllByteArr[byteIdx + 1] << 8) | this->hllByteArr[byteIdx];
+ uint16_t curMasked = (this->hllByteArr_[byteIdx + 1] << 8) | this->hllByteArr_[byteIdx];
curMasked &= (~(HllUtil<A>::VAL_MASK_6 << shift));
const uint16_t insert = curMasked | valShifted;
- this->hllByteArr[byteIdx] = insert & 0xFF;
- this->hllByteArr[byteIdx + 1] = (insert & 0xFF00) >> 8;
+ this->hllByteArr_[byteIdx] = insert & 0xFF;
+ this->hllByteArr_[byteIdx + 1] = (insert & 0xFF00) >> 8;
}
template<typename A>
-int Hll6Array<A>::getHllByteArrBytes() const {
- return this->hll6ArrBytes(this->lgConfigK);
+uint32_t Hll6Array<A>::getHllByteArrBytes() const {
+ return this->hll6ArrBytes(this->lgConfigK_);
}
template<typename A>
-HllSketchImpl<A>* Hll6Array<A>::couponUpdate(const int coupon) {
+HllSketchImpl<A>* Hll6Array<A>::couponUpdate(uint32_t coupon) {
internalCouponUpdate(coupon);
return this;
}
template<typename A>
-void Hll6Array<A>::internalCouponUpdate(const int coupon) {
- const int configKmask = (1 << this->lgConfigK) - 1;
- const int slotNo = HllUtil<A>::getLow26(coupon) & configKmask;
- const int newVal = HllUtil<A>::getValue(coupon);
+void Hll6Array<A>::internalCouponUpdate(uint32_t coupon) {
+ const uint32_t configKmask = (1 << this->lgConfigK_) - 1;
+ const uint32_t slotNo = HllUtil<A>::getLow26(coupon) & configKmask;
+ const uint8_t newVal = HllUtil<A>::getValue(coupon);
- const int curVal = getSlot(slotNo);
+ const uint8_t curVal = getSlot(slotNo);
if (newVal > curVal) {
putSlot(slotNo, newVal);
this->hipAndKxQIncrementalUpdate(curVal, newVal);
if (curVal == 0) {
- this->numAtCurMin--; // interpret numAtCurMin as num zeros
+ this->numAtCurMin_--; // interpret numAtCurMin as num zeros
}
}
}
template<typename A>
void Hll6Array<A>::mergeHll(const HllArray<A>& src) {
- for (auto coupon: src) {
+ for (const auto coupon: src) {
internalCouponUpdate(coupon);
}
}
diff --git a/hll/include/Hll6Array.hpp b/hll/include/Hll6Array.hpp
index 03370b2..3c821c6 100644
--- a/hll/include/Hll6Array.hpp
+++ b/hll/include/Hll6Array.hpp
@@ -30,23 +30,23 @@
template<typename A>
class Hll6Array final : public HllArray<A> {
public:
- Hll6Array(int lgConfigK, bool startFullSize, const A& allocator);
+ Hll6Array(uint8_t lgConfigK, bool startFullSize, const A& allocator);
virtual ~Hll6Array() = default;
virtual std::function<void(HllSketchImpl<A>*)> get_deleter() const;
virtual Hll6Array* copy() const;
- inline uint8_t getSlot(int slotNo) const;
- inline void putSlot(int slotNo, uint8_t value);
+ inline uint8_t getSlot(uint32_t slotNo) const;
+ inline void putSlot(uint32_t slotNo, uint8_t value);
- virtual HllSketchImpl<A>* couponUpdate(int coupon) final;
+ virtual HllSketchImpl<A>* couponUpdate(uint32_t coupon) final;
void mergeHll(const HllArray<A>& src);
- virtual int getHllByteArrBytes() const;
+ virtual uint32_t getHllByteArrBytes() const;
private:
- void internalCouponUpdate(int coupon);
+ void internalCouponUpdate(uint32_t coupon);
};
}
diff --git a/hll/include/Hll8Array-internal.hpp b/hll/include/Hll8Array-internal.hpp
index f27a796..d4de2a1 100644
--- a/hll/include/Hll8Array-internal.hpp
+++ b/hll/include/Hll8Array-internal.hpp
@@ -25,11 +25,11 @@
namespace datasketches {
template<typename A>
-Hll8Array<A>::Hll8Array(const int lgConfigK, const bool startFullSize, const A& allocator):
+Hll8Array<A>::Hll8Array(uint8_t lgConfigK, bool startFullSize, const A& allocator):
HllArray<A>(lgConfigK, target_hll_type::HLL_8, startFullSize, allocator)
{
const int numBytes = this->hll8ArrBytes(lgConfigK);
- this->hllByteArr.resize(numBytes, 0);
+ this->hllByteArr_.resize(numBytes, 0);
}
template<typename A>
@@ -51,45 +51,45 @@
}
template<typename A>
-uint8_t Hll8Array<A>::getSlot(const int slotNo) const {
- return this->hllByteArr[slotNo];
+uint8_t Hll8Array<A>::getSlot(uint32_t slotNo) const {
+ return this->hllByteArr_[slotNo];
}
template<typename A>
-void Hll8Array<A>::putSlot(const int slotNo, uint8_t value) {
- this->hllByteArr[slotNo] = value;
+void Hll8Array<A>::putSlot(uint32_t slotNo, uint8_t value) {
+ this->hllByteArr_[slotNo] = value;
}
template<typename A>
-int Hll8Array<A>::getHllByteArrBytes() const {
- return this->hll8ArrBytes(this->lgConfigK);
+uint32_t Hll8Array<A>::getHllByteArrBytes() const {
+ return this->hll8ArrBytes(this->lgConfigK_);
}
template<typename A>
-HllSketchImpl<A>* Hll8Array<A>::couponUpdate(int coupon) {
+HllSketchImpl<A>* Hll8Array<A>::couponUpdate(uint32_t coupon) {
internalCouponUpdate(coupon);
return this;
}
template<typename A>
-void Hll8Array<A>::internalCouponUpdate(int coupon) {
- const int configKmask = (1 << this->lgConfigK) - 1;
- const int slotNo = HllUtil<A>::getLow26(coupon) & configKmask;
- const int newVal = HllUtil<A>::getValue(coupon);
+void Hll8Array<A>::internalCouponUpdate(uint32_t coupon) {
+ const uint32_t configKmask = (1 << this->lgConfigK_) - 1;
+ const uint32_t slotNo = HllUtil<A>::getLow26(coupon) & configKmask;
+ const uint8_t newVal = HllUtil<A>::getValue(coupon);
- const int curVal = getSlot(slotNo);
+ const uint8_t curVal = getSlot(slotNo);
if (newVal > curVal) {
putSlot(slotNo, newVal);
this->hipAndKxQIncrementalUpdate(curVal, newVal);
if (curVal == 0) {
- this->numAtCurMin--; // interpret numAtCurMin as num zeros
+ this->numAtCurMin_--; // interpret numAtCurMin as num zeros
}
}
}
template<typename A>
void Hll8Array<A>::mergeList(const CouponList<A>& src) {
- for (auto coupon: src) {
+ for (const auto coupon: src) {
internalCouponUpdate(coupon);
}
}
@@ -97,45 +97,45 @@
template<typename A>
void Hll8Array<A>::mergeHll(const HllArray<A>& src) {
// at this point src_k >= dst_k
- const int src_k = 1 << src.getLgConfigK();
- const int dst_mask = (1 << this->getLgConfigK()) - 1;
+ const uint32_t src_k = 1 << src.getLgConfigK();
+ const uint32_t dst_mask = (1 << this->getLgConfigK()) - 1;
// duplication below is to avoid a virtual method call in a loop
if (src.getTgtHllType() == target_hll_type::HLL_8) {
- for (int i = 0; i < src_k; i++) {
+ for (uint32_t i = 0; i < src_k; i++) {
const uint8_t new_v = static_cast<const Hll8Array<A>&>(src).getSlot(i);
- const int j = i & dst_mask;
- const uint8_t old_v = this->hllByteArr[j];
+ const uint32_t j = i & dst_mask;
+ const uint8_t old_v = this->hllByteArr_[j];
if (new_v > old_v) {
- this->hllByteArr[j] = new_v;
+ this->hllByteArr_[j] = new_v;
this->hipAndKxQIncrementalUpdate(old_v, new_v);
if (old_v == 0) {
- this->numAtCurMin--;
+ this->numAtCurMin_--;
}
}
}
} else if (src.getTgtHllType() == target_hll_type::HLL_6) {
- for (int i = 0; i < src_k; i++) {
+ for (uint32_t i = 0; i < src_k; i++) {
const uint8_t new_v = static_cast<const Hll6Array<A>&>(src).getSlot(i);
- const int j = i & dst_mask;
- const uint8_t old_v = this->hllByteArr[j];
+ const uint32_t j = i & dst_mask;
+ const uint8_t old_v = this->hllByteArr_[j];
if (new_v > old_v) {
- this->hllByteArr[j] = new_v;
+ this->hllByteArr_[j] = new_v;
this->hipAndKxQIncrementalUpdate(old_v, new_v);
if (old_v == 0) {
- this->numAtCurMin--;
+ this->numAtCurMin_--;
}
}
}
} else { // HLL_4
- for (int i = 0; i < src_k; i++) {
+ for (uint32_t i = 0; i < src_k; i++) {
const uint8_t new_v = static_cast<const Hll4Array<A>&>(src).get_value(i);
- const int j = i & dst_mask;
- const uint8_t old_v = this->hllByteArr[j];
+ const uint32_t j = i & dst_mask;
+ const uint8_t old_v = this->hllByteArr_[j];
if (new_v > old_v) {
- this->hllByteArr[j] = new_v;
+ this->hllByteArr_[j] = new_v;
this->hipAndKxQIncrementalUpdate(old_v, new_v);
if (old_v == 0) {
- this->numAtCurMin--;
+ this->numAtCurMin_--;
}
}
}
diff --git a/hll/include/Hll8Array.hpp b/hll/include/Hll8Array.hpp
index ea9a5bd..54db472 100644
--- a/hll/include/Hll8Array.hpp
+++ b/hll/include/Hll8Array.hpp
@@ -30,24 +30,24 @@
template<typename A>
class Hll8Array final : public HllArray<A> {
public:
- Hll8Array(int lgConfigK, bool startFullSize, const A& allocator);
+ Hll8Array(uint8_t lgConfigK, bool startFullSize, const A& allocator);
virtual ~Hll8Array() = default;
virtual std::function<void(HllSketchImpl<A>*)> get_deleter() const;
virtual Hll8Array<A>* copy() const;
- inline uint8_t getSlot(int slotNo) const;
- inline void putSlot(int slotNo, uint8_t value);
+ inline uint8_t getSlot(uint32_t slotNo) const;
+ inline void putSlot(uint32_t slotNo, uint8_t value);
- virtual HllSketchImpl<A>* couponUpdate(int coupon) final;
+ virtual HllSketchImpl<A>* couponUpdate(uint32_t coupon) final;
void mergeList(const CouponList<A>& src);
void mergeHll(const HllArray<A>& src);
- virtual int getHllByteArrBytes() const;
+ virtual uint32_t getHllByteArrBytes() const;
private:
- inline void internalCouponUpdate(int coupon);
+ inline void internalCouponUpdate(uint32_t coupon);
};
}
diff --git a/hll/include/HllArray-internal.hpp b/hll/include/HllArray-internal.hpp
index 95ef116..a0b3fd8 100644
--- a/hll/include/HllArray-internal.hpp
+++ b/hll/include/HllArray-internal.hpp
@@ -35,19 +35,19 @@
namespace datasketches {
template<typename A>
-HllArray<A>::HllArray(const int lgConfigK, const target_hll_type tgtHllType, bool startFullSize, const A& allocator):
+HllArray<A>::HllArray(uint8_t lgConfigK, target_hll_type tgtHllType, bool startFullSize, const A& allocator):
HllSketchImpl<A>(lgConfigK, tgtHllType, hll_mode::HLL, startFullSize),
-hipAccum(0.0),
-kxq0(1 << lgConfigK),
-kxq1(0.0),
-hllByteArr(allocator),
-curMin(0),
-numAtCurMin(1 << lgConfigK),
-oooFlag(false)
+hipAccum_(0.0),
+kxq0_(1 << lgConfigK),
+kxq1_(0.0),
+hllByteArr_(allocator),
+curMin_(0),
+numAtCurMin_(1 << lgConfigK),
+oooFlag_(false)
{}
template<typename A>
-HllArray<A>* HllArray<A>::copyAs(const target_hll_type tgtHllType) const {
+HllArray<A>* HllArray<A>::copyAs(target_hll_type tgtHllType) const {
if (tgtHllType == this->getTgtHllType()) {
return static_cast<HllArray*>(copy());
}
@@ -87,10 +87,10 @@
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 int lgK = (int) data[HllUtil<A>::LG_K_BYTE];
- const int curMin = (int) data[HllUtil<A>::HLL_CUR_MIN_BYTE];
+ const uint8_t lgK = data[HllUtil<A>::LG_K_BYTE];
+ const uint8_t curMin = data[HllUtil<A>::HLL_CUR_MIN_BYTE];
- const int arrayBytes = hllArrBytes(tgtHllType, lgK);
+ const uint32_t arrayBytes = hllArrBytes(tgtHllType, lgK);
if (len < static_cast<size_t>(HllUtil<A>::HLL_BYTE_ARR_START + arrayBytes)) {
throw std::out_of_range("Input array too small to hold sketch image");
}
@@ -100,7 +100,7 @@
std::memcpy(&kxq0, data + HllUtil<A>::KXQ0_DOUBLE, sizeof(double));
std::memcpy(&kxq1, data + HllUtil<A>::KXQ1_DOUBLE, sizeof(double));
- int numAtCurMin, auxCount;
+ 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));
@@ -108,7 +108,7 @@
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
- int auxLgIntArrSize = (int) data[4];
+ uint8_t auxLgIntArrSize = data[4];
const size_t offset = HllUtil<A>::HLL_BYTE_ARR_START + arrayBytes;
const uint8_t* auxDataStart = data + offset;
auxHashMap = AuxHashMap<A>::deserialize(auxDataStart, len - offset, lgK, auxCount, auxLgIntArrSize, comapctFlag, allocator);
@@ -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 + HllUtil<A>::HLL_BYTE_ARR_START, arrayBytes);
if (auxHashMap != nullptr)
((Hll4Array<A>*)sketch)->putAuxHashMap(auxHashMap);
@@ -157,8 +157,8 @@
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 int lgK = (int) listHeader[HllUtil<A>::LG_K_BYTE];
- const int curMin = (int) listHeader[HllUtil<A>::HLL_CUR_MIN_BYTE];
+ const uint8_t lgK = listHeader[HllUtil<A>::LG_K_BYTE];
+ const uint8_t curMin = listHeader[HllUtil<A>::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;
@@ -173,14 +173,14 @@
sketch->putKxQ0(kxq0);
sketch->putKxQ1(kxq1);
- const auto numAtCurMin = read<int>(is);
- const auto auxCount = read<int>(is);
+ const auto numAtCurMin = read<uint32_t>(is);
+ const auto auxCount = read<uint32_t>(is);
sketch->putNumAtCurMin(numAtCurMin);
- read(is, sketch->hllByteArr.data(), sketch->getHllByteArrBytes());
+ read(is, sketch->hllByteArr_.data(), sketch->getHllByteArrBytes());
if (auxCount > 0) { // necessarily TgtHllType == HLL_4
- int auxLgIntArrSize = listHeader[4];
+ uint8_t auxLgIntArrSize = listHeader[4];
AuxHashMap<A>* auxHashMap = AuxHashMap<A>::deserialize(is, lgK, auxCount, auxLgIntArrSize, comapctFlag, allocator);
((Hll4Array<A>*)sketch)->putAuxHashMap(auxHashMap);
}
@@ -201,28 +201,28 @@
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_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>::HLL_CUR_MIN_BYTE] = static_cast<uint8_t>(curMin_);
bytes[HllUtil<A>::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(int));
- const int auxCount = (auxHashMap == nullptr ? 0 : auxHashMap->getAuxCount());
- std::memcpy(bytes + HllUtil<A>::AUX_COUNT_INT, &auxCount, sizeof(int));
+ 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));
+ const uint32_t auxCount = (auxHashMap == nullptr ? 0 : auxHashMap->getAuxCount());
+ std::memcpy(bytes + HllUtil<A>::AUX_COUNT_INT, &auxCount, sizeof(uint32_t));
- const int hllByteArrBytes = getHllByteArrBytes();
- std::memcpy(bytes + getMemDataStart(), hllByteArr.data(), hllByteArrBytes);
+ const uint32_t hllByteArrBytes = getHllByteArrBytes();
+ std::memcpy(bytes + getMemDataStart(), hllByteArr_.data(), hllByteArrBytes);
// aux map if HLL_4
- if (this->tgtHllType == HLL_4) {
+ if (this->tgtHllType_ == HLL_4) {
bytes += getMemDataStart() + hllByteArrBytes; // start of auxHashMap
if (auxHashMap != nullptr) {
if (compact) {
- for (uint32_t coupon: *auxHashMap) {
+ for (const uint32_t coupon: *auxHashMap) {
std::memcpy(bytes, &coupon, sizeof(coupon));
bytes += sizeof(coupon);
}
@@ -231,8 +231,8 @@
}
} else if (!compact) {
// if updatable, we write even if currently unused so the binary can be wrapped
- int auxBytes = 4 << HllUtil<A>::LG_AUX_ARR_INTS[this->lgConfigK];
- std::fill_n(bytes, auxBytes, 0);
+ uint32_t auxBytes = 4 << HllUtil<A>::LG_AUX_ARR_INTS[this->lgConfigK_];
+ std::fill_n(bytes, auxBytes, static_cast<uint8_t>(0));
}
}
@@ -240,48 +240,47 @@
}
template<typename A>
-void HllArray<A>::serialize(std::ostream& os, const bool compact) const {
+void HllArray<A>::serialize(std::ostream& os, bool compact) const {
// header
- const uint8_t preInts(getPreInts());
+ const uint8_t preInts = getPreInts();
write(os, preInts);
- const uint8_t serialVersion(HllUtil<A>::SER_VER);
+ const uint8_t serialVersion = HllUtil<A>::SER_VER;
write(os, serialVersion);
- const uint8_t familyId(HllUtil<A>::FAMILY_ID);
+ const uint8_t familyId = HllUtil<A>::FAMILY_ID;
write(os, familyId);
- const uint8_t lgKByte((uint8_t) this->lgConfigK);
+ const uint8_t lgKByte = this->lgConfigK_;
write(os, lgKByte);
AuxHashMap<A>* auxHashMap = getAuxHashMap();
- uint8_t lgArrByte(0);
+ uint8_t lgArrByte = 0;
if (auxHashMap != nullptr) {
lgArrByte = auxHashMap->getLgAuxArrInts();
}
write(os, lgArrByte);
- const uint8_t flagsByte(this->makeFlagsByte(compact));
+ const uint8_t flagsByte = this->makeFlagsByte(compact);
write(os, flagsByte);
- const uint8_t curMinByte((uint8_t) curMin);
- write(os, curMinByte);
- const uint8_t modeByte(this->makeModeByte());
+ write(os, curMin_);
+ const uint8_t modeByte = this->makeModeByte();
write(os, modeByte);
// estimator data
- write(os, hipAccum);
- write(os, kxq0);
- write(os, kxq1);
+ write(os, hipAccum_);
+ write(os, kxq0_);
+ write(os, kxq1_);
// array data
- write(os, numAtCurMin);
+ write(os, numAtCurMin_);
- const int auxCount = (auxHashMap == nullptr ? 0 : auxHashMap->getAuxCount());
+ const uint32_t auxCount = (auxHashMap == nullptr ? 0 : auxHashMap->getAuxCount());
write(os, auxCount);
- write(os, hllByteArr.data(), getHllByteArrBytes());
+ write(os, hllByteArr_.data(), getHllByteArrBytes());
// aux map if HLL_4
- if (this->tgtHllType == HLL_4) {
+ if (this->tgtHllType_ == HLL_4) {
if (auxHashMap != nullptr) {
if (compact) {
- for (uint32_t coupon: *auxHashMap) {
+ for (const uint32_t coupon: *auxHashMap) {
write(os, coupon);
}
} else {
@@ -289,15 +288,15 @@
}
} else if (!compact) {
// if updatable, we write even if currently unused so the binary can be wrapped
- int auxBytes = 4 << HllUtil<A>::LG_AUX_ARR_INTS[this->lgConfigK];
- std::fill_n(std::ostreambuf_iterator<char>(os), auxBytes, 0);
+ uint32_t auxBytes = 4 << HllUtil<A>::LG_AUX_ARR_INTS[this->lgConfigK_];
+ std::fill_n(std::ostreambuf_iterator<char>(os), auxBytes, static_cast<char>(0));
}
}
}
template<typename A>
double HllArray<A>::getEstimate() const {
- if (oooFlag) {
+ if (oooFlag_) {
return getCompositeEstimate();
}
return getHipAccum();
@@ -319,50 +318,50 @@
* the very small values <= k where curMin = 0 still apply.
*/
template<typename A>
-double HllArray<A>::getLowerBound(const int numStdDev) const {
+double HllArray<A>::getLowerBound(uint8_t numStdDev) const {
HllUtil<A>::checkNumStdDev(numStdDev);
- const int configK = 1 << this->lgConfigK;
- const double numNonZeros = ((curMin == 0) ? (configK - numAtCurMin) : configK);
+ const uint32_t configK = 1 << this->lgConfigK_;
+ const double numNonZeros = ((curMin_ == 0) ? (configK - numAtCurMin_) : configK);
double estimate;
double rseFactor;
- if (oooFlag) {
+ if (oooFlag_) {
estimate = getCompositeEstimate();
rseFactor = HllUtil<A>::HLL_NON_HIP_RSE_FACTOR;
} else {
- estimate = hipAccum;
+ estimate = hipAccum_;
rseFactor = HllUtil<A>::HLL_HIP_RSE_FACTOR;
}
double relErr;
- if (this->lgConfigK > 12) {
+ if (this->lgConfigK_ > 12) {
relErr = (numStdDev * rseFactor) / sqrt(configK);
} else {
- relErr = HllUtil<A>::getRelErr(false, oooFlag, this->lgConfigK, numStdDev);
+ relErr = HllUtil<A>::getRelErr(false, oooFlag_, this->lgConfigK_, numStdDev);
}
return fmax(estimate / (1.0 + relErr), numNonZeros);
}
template<typename A>
-double HllArray<A>::getUpperBound(const int numStdDev) const {
+double HllArray<A>::getUpperBound(uint8_t numStdDev) const {
HllUtil<A>::checkNumStdDev(numStdDev);
- const int configK = 1 << this->lgConfigK;
+ const uint32_t configK = 1 << this->lgConfigK_;
double estimate;
double rseFactor;
- if (oooFlag) {
+ if (oooFlag_) {
estimate = getCompositeEstimate();
rseFactor = HllUtil<A>::HLL_NON_HIP_RSE_FACTOR;
} else {
- estimate = hipAccum;
+ estimate = hipAccum_;
rseFactor = HllUtil<A>::HLL_HIP_RSE_FACTOR;
}
double relErr;
- if (this->lgConfigK > 12) {
+ if (this->lgConfigK_ > 12) {
relErr = (-1.0) * (numStdDev * rseFactor) / sqrt(configK);
} else {
- relErr = HllUtil<A>::getRelErr(true, oooFlag, this->lgConfigK, numStdDev);
+ relErr = HllUtil<A>::getRelErr(true, oooFlag_, this->lgConfigK_, numStdDev);
}
return estimate / (1.0 + relErr);
}
@@ -376,21 +375,21 @@
// Original C: again-two-registers.c hhb_get_composite_estimate L1489
template<typename A>
double HllArray<A>::getCompositeEstimate() const {
- const double rawEst = getHllRawEstimate(this->lgConfigK, kxq0 + kxq1);
+ const double rawEst = getHllRawEstimate();
- const double* xArr = CompositeInterpolationXTable<A>::get_x_arr(this->lgConfigK);
- const int xArrLen = CompositeInterpolationXTable<A>::get_x_arr_length();
- const double yStride = CompositeInterpolationXTable<A>::get_y_stride(this->lgConfigK);
+ const double* xArr = CompositeInterpolationXTable<A>::get_x_arr(this->lgConfigK_);
+ const uint32_t xArrLen = CompositeInterpolationXTable<A>::get_x_arr_length();
+ const double yStride = CompositeInterpolationXTable<A>::get_y_stride(this->lgConfigK_);
if (rawEst < xArr[0]) {
return 0;
}
- const int xArrLenM1 = xArrLen - 1;
+ const uint32_t xArrLenM1 = xArrLen - 1;
if (rawEst > xArr[xArrLenM1]) {
- double finalY = yStride * xArrLenM1;
- double factor = finalY / xArr[xArrLenM1];
+ const double finalY = yStride * xArrLenM1;
+ const double factor = finalY / xArr[xArrLenM1];
return rawEst * factor;
}
@@ -399,10 +398,9 @@
// We need to completely avoid the linear_counting estimator if it might have a crazy value.
// Empirical evidence suggests that the threshold 3*k will keep us safe if 2^4 <= k <= 2^21.
- if (adjEst > (3 << this->lgConfigK)) { return adjEst; }
+ if (adjEst > (3 << this->lgConfigK_)) { return adjEst; }
- const double linEst =
- getHllBitMapEstimate(this->lgConfigK, curMin, numAtCurMin);
+ const double linEst = getHllBitMapEstimate();
// Bias is created when the value of an estimator is compared with a threshold to decide whether
// to use that estimator or a different one.
@@ -414,70 +412,70 @@
// The following constants comes from empirical measurements of the crossover point
// between the average error of the linear estimator and the adjusted hll estimator
double crossOver = 0.64;
- if (this->lgConfigK == 4) { crossOver = 0.718; }
- else if (this->lgConfigK == 5) { crossOver = 0.672; }
+ if (this->lgConfigK_ == 4) { crossOver = 0.718; }
+ else if (this->lgConfigK_ == 5) { crossOver = 0.672; }
- return (avgEst > (crossOver * (1 << this->lgConfigK))) ? adjEst : linEst;
+ return (avgEst > (crossOver * (1 << this->lgConfigK_))) ? adjEst : linEst;
}
template<typename A>
double HllArray<A>::getKxQ0() const {
- return kxq0;
+ return kxq0_;
}
template<typename A>
double HllArray<A>::getKxQ1() const {
- return kxq1;
+ return kxq1_;
}
template<typename A>
double HllArray<A>::getHipAccum() const {
- return hipAccum;
+ return hipAccum_;
}
template<typename A>
-int HllArray<A>::getCurMin() const {
- return curMin;
+uint8_t HllArray<A>::getCurMin() const {
+ return curMin_;
}
template<typename A>
-int HllArray<A>::getNumAtCurMin() const {
- return numAtCurMin;
+uint32_t HllArray<A>::getNumAtCurMin() const {
+ return numAtCurMin_;
}
template<typename A>
-void HllArray<A>::putKxQ0(const double kxq0) {
- this->kxq0 = kxq0;
+void HllArray<A>::putKxQ0(double kxq0) {
+ kxq0_ = kxq0;
}
template<typename A>
-void HllArray<A>::putKxQ1(const double kxq1) {
- this->kxq1 = kxq1;
+void HllArray<A>::putKxQ1(double kxq1) {
+ kxq1_ = kxq1;
}
template<typename A>
-void HllArray<A>::putHipAccum(const double hipAccum) {
- this->hipAccum = hipAccum;
+void HllArray<A>::putHipAccum(double hipAccum) {
+ hipAccum_ = hipAccum;
}
template<typename A>
-void HllArray<A>::putCurMin(const int curMin) {
- this->curMin = curMin;
+void HllArray<A>::putCurMin(uint8_t curMin) {
+ curMin_ = curMin;
}
template<typename A>
-void HllArray<A>::putNumAtCurMin(const int numAtCurMin) {
- this->numAtCurMin = numAtCurMin;
+void HllArray<A>::putNumAtCurMin(uint32_t numAtCurMin) {
+ numAtCurMin_ = numAtCurMin;
}
template<typename A>
void HllArray<A>::decNumAtCurMin() {
- --numAtCurMin;
+ --numAtCurMin_;
}
template<typename A>
-void HllArray<A>::addToHipAccum(const double delta) {
- hipAccum += delta;
+void HllArray<A>::addToHipAccum(double delta) {
+ hipAccum_ += delta;
}
template<typename A>
@@ -487,22 +485,22 @@
template<typename A>
bool HllArray<A>::isEmpty() const {
- const int configK = 1 << this->lgConfigK;
+ const uint32_t configK = 1 << this->lgConfigK_;
return (getCurMin() == 0) && (getNumAtCurMin() == configK);
}
template<typename A>
void HllArray<A>::putOutOfOrderFlag(bool flag) {
- oooFlag = flag;
+ oooFlag_ = flag;
}
template<typename A>
bool HllArray<A>::isOutOfOrderFlag() const {
- return oooFlag;
+ return oooFlag_;
}
template<typename A>
-int HllArray<A>::hllArrBytes(target_hll_type tgtHllType, int lgConfigK) {
+uint32_t HllArray<A>::hllArrBytes(target_hll_type tgtHllType, uint8_t lgConfigK) {
switch (tgtHllType) {
case HLL_4:
return hll4ArrBytes(lgConfigK);
@@ -516,40 +514,40 @@
}
template<typename A>
-int HllArray<A>::hll4ArrBytes(const int lgConfigK) {
+uint32_t HllArray<A>::hll4ArrBytes(uint8_t lgConfigK) {
return 1 << (lgConfigK - 1);
}
template<typename A>
-int HllArray<A>::hll6ArrBytes(const int lgConfigK) {
- const int numSlots = 1 << lgConfigK;
+uint32_t HllArray<A>::hll6ArrBytes(uint8_t lgConfigK) {
+ const uint32_t numSlots = 1 << lgConfigK;
return ((numSlots * 3) >> 2) + 1;
}
template<typename A>
-int HllArray<A>::hll8ArrBytes(const int lgConfigK) {
+uint32_t HllArray<A>::hll8ArrBytes(uint8_t lgConfigK) {
return 1 << lgConfigK;
}
template<typename A>
-int HllArray<A>::getMemDataStart() const {
+uint32_t HllArray<A>::getMemDataStart() const {
return HllUtil<A>::HLL_BYTE_ARR_START;
}
template<typename A>
-int HllArray<A>::getUpdatableSerializationBytes() const {
+uint32_t HllArray<A>::getUpdatableSerializationBytes() const {
return HllUtil<A>::HLL_BYTE_ARR_START + getHllByteArrBytes();
}
template<typename A>
-int HllArray<A>::getCompactSerializationBytes() const {
+uint32_t HllArray<A>::getCompactSerializationBytes() const {
AuxHashMap<A>* auxHashMap = getAuxHashMap();
- const int auxCountBytes = ((auxHashMap == nullptr) ? 0 : auxHashMap->getCompactSizeBytes());
+ const uint32_t auxCountBytes = ((auxHashMap == nullptr) ? 0 : auxHashMap->getCompactSizeBytes());
return HllUtil<A>::HLL_BYTE_ARR_START + getHllByteArrBytes() + auxCountBytes;
}
template<typename A>
-int HllArray<A>::getPreInts() const {
+uint8_t HllArray<A>::getPreInts() const {
return HllUtil<A>::HLL_PREINTS;
}
@@ -560,14 +558,14 @@
template<typename A>
void HllArray<A>::hipAndKxQIncrementalUpdate(uint8_t oldValue, uint8_t newValue) {
- const int configK = 1 << this->getLgConfigK();
+ const uint32_t configK = 1 << this->getLgConfigK();
// update hip BEFORE updating kxq
- if (!oooFlag) hipAccum += configK / (kxq0 + kxq1);
+ if (!oooFlag_) hipAccum_ += configK / (kxq0_ + kxq1_);
// update kxq0 and kxq1; subtract first, then add
- if (oldValue < 32) { kxq0 -= INVERSE_POWERS_OF_2[oldValue]; }
- else { kxq1 -= INVERSE_POWERS_OF_2[oldValue]; }
- if (newValue < 32) { kxq0 += INVERSE_POWERS_OF_2[newValue]; }
- else { kxq1 += INVERSE_POWERS_OF_2[newValue]; }
+ if (oldValue < 32) { kxq0_ -= INVERSE_POWERS_OF_2[oldValue]; }
+ else { kxq1_ -= INVERSE_POWERS_OF_2[oldValue]; }
+ if (newValue < 32) { kxq0_ += INVERSE_POWERS_OF_2[newValue]; }
+ else { kxq1_ += INVERSE_POWERS_OF_2[newValue]; }
}
/**
@@ -577,74 +575,74 @@
*/
//In C: again-two-registers.c hhb_get_improved_linear_counting_estimate L1274
template<typename A>
-double HllArray<A>::getHllBitMapEstimate(const int lgConfigK, const int curMin, const int numAtCurMin) const {
- const int configK = 1 << lgConfigK;
- const int numUnhitBuckets = ((curMin == 0) ? numAtCurMin : 0);
+double HllArray<A>::getHllBitMapEstimate() const {
+ const uint32_t configK = 1 << lgConfigK_;
+ const uint32_t numUnhitBuckets = curMin_ == 0 ? numAtCurMin_ : 0;
//This will eventually go away.
if (numUnhitBuckets == 0) {
return configK * log(configK / 0.5);
}
- const int numHitBuckets = configK - numUnhitBuckets;
+ const uint32_t numHitBuckets = configK - numUnhitBuckets;
return HarmonicNumbers<A>::getBitMapEstimate(configK, numHitBuckets);
}
//In C: again-two-registers.c hhb_get_raw_estimate L1167
template<typename A>
-double HllArray<A>::getHllRawEstimate(const int lgConfigK, const double kxqSum) const {
- const int configK = 1 << lgConfigK;
+double HllArray<A>::getHllRawEstimate() const {
+ const uint32_t configK = 1 << this->lgConfigK_;
double correctionFactor;
- if (lgConfigK == 4) { correctionFactor = 0.673; }
- else if (lgConfigK == 5) { correctionFactor = 0.697; }
- else if (lgConfigK == 6) { correctionFactor = 0.709; }
+ if (this->lgConfigK_ == 4) { correctionFactor = 0.673; }
+ else if (this->lgConfigK_ == 5) { correctionFactor = 0.697; }
+ else if (this->lgConfigK_ == 6) { correctionFactor = 0.709; }
else { correctionFactor = 0.7213 / (1.0 + (1.079 / configK)); }
- const double hyperEst = (correctionFactor * configK * configK) / kxqSum;
+ const double hyperEst = (correctionFactor * configK * configK) / (kxq0_ + kxq1_);
return hyperEst;
}
template<typename A>
typename HllArray<A>::const_iterator HllArray<A>::begin(bool all) const {
- return const_iterator(hllByteArr.data(), 1 << this->lgConfigK, 0, this->tgtHllType, nullptr, 0, all);
+ return const_iterator(hllByteArr_.data(), 1 << this->lgConfigK_, 0, this->tgtHllType_, nullptr, 0, all);
}
template<typename A>
typename HllArray<A>::const_iterator HllArray<A>::end() const {
- return const_iterator(hllByteArr.data(), 1 << this->lgConfigK, 1 << this->lgConfigK, this->tgtHllType, nullptr, 0, false);
+ return const_iterator(hllByteArr_.data(), 1 << this->lgConfigK_, 1 << this->lgConfigK_, this->tgtHllType_, nullptr, 0, false);
}
template<typename A>
-HllArray<A>::const_iterator::const_iterator(const uint8_t* array, size_t array_size, size_t index, target_hll_type hll_type, const AuxHashMap<A>* exceptions, uint8_t offset, bool all):
-array(array), array_size(array_size), index(index), hll_type(hll_type), exceptions(exceptions), offset(offset), all(all)
+HllArray<A>::const_iterator::const_iterator(const uint8_t* array, uint32_t array_size, uint32_t index, target_hll_type hll_type, const AuxHashMap<A>* exceptions, uint8_t offset, bool all):
+array_(array), array_size_(array_size), index_(index), hll_type_(hll_type), exceptions_(exceptions), offset_(offset), all_(all)
{
- while (this->index < array_size) {
- value = get_value(array, this->index, hll_type, exceptions, offset);
- if (all || value != HllUtil<A>::EMPTY) break;
- this->index++;
+ while (index_ < array_size_) {
+ value_ = get_value(array_, index_, hll_type_, exceptions_, offset_);
+ if (all_ || value_ != HllUtil<A>::EMPTY) break;
+ ++index_;
}
}
template<typename A>
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;
+ while (++index_ < array_size_) {
+ value_ = get_value(array_, index_, hll_type_, exceptions_, offset_);
+ if (all_ || value_ != HllUtil<A>::EMPTY) break;
}
return *this;
}
template<typename A>
bool HllArray<A>::const_iterator::operator!=(const const_iterator& other) const {
- return index != other.index;
+ return index_ != other.index_;
}
template<typename A>
uint32_t HllArray<A>::const_iterator::operator*() const {
- return HllUtil<A>::pair(index, value);
+ return HllUtil<A>::pair(index_, value_);
}
template<typename A>
-uint8_t HllArray<A>::const_iterator::get_value(const uint8_t* array, size_t index, target_hll_type hll_type, const AuxHashMap<A>* exceptions, uint8_t offset) {
+uint8_t HllArray<A>::const_iterator::get_value(const uint8_t* array, uint32_t index, target_hll_type hll_type, const AuxHashMap<A>* exceptions, uint8_t offset) {
if (hll_type == target_hll_type::HLL_4) {
uint8_t value = array[index >> 1];
if ((index & 1) > 0) { // odd
@@ -657,9 +655,9 @@
}
return value + offset;
} else if (hll_type == target_hll_type::HLL_6) {
- const int start_bit = index * 6;
- const int shift = start_bit & 0x7;
- const int byte_idx = start_bit >> 3;
+ const size_t start_bit = index * 6;
+ 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;
}
@@ -669,7 +667,7 @@
template<typename A>
A HllArray<A>::getAllocator() const {
- return hllByteArr.get_allocator();
+ return hllByteArr_.get_allocator();
}
}
diff --git a/hll/include/HllArray.hpp b/hll/include/HllArray.hpp
index e7be8c1..60aee76 100644
--- a/hll/include/HllArray.hpp
+++ b/hll/include/HllArray.hpp
@@ -31,7 +31,7 @@
template<typename A>
class HllArray : public HllSketchImpl<A> {
public:
- HllArray(int lgConfigK, target_hll_type tgtHllType, bool startFullSize, const A& allocator);
+ HllArray(uint8_t lgConfigK, target_hll_type tgtHllType, bool startFullSize, const A& allocator);
static HllArray* newHll(const void* bytes, size_t len, const A& allocator);
static HllArray* newHll(std::istream& is, const A& allocator);
@@ -45,25 +45,25 @@
virtual HllArray* copy() const = 0;
virtual HllArray* copyAs(target_hll_type tgtHllType) const;
- virtual HllSketchImpl<A>* couponUpdate(int coupon) = 0;
+ virtual HllSketchImpl<A>* couponUpdate(uint32_t coupon) = 0;
virtual double getEstimate() const;
virtual double getCompositeEstimate() const;
- virtual double getLowerBound(int numStdDev) const;
- virtual double getUpperBound(int numStdDev) const;
+ virtual double getLowerBound(uint8_t numStdDev) const;
+ virtual double getUpperBound(uint8_t numStdDev) const;
inline void addToHipAccum(double delta);
inline void decNumAtCurMin();
- inline int getCurMin() const;
- inline int getNumAtCurMin() const;
+ inline uint8_t getCurMin() const;
+ inline uint32_t getNumAtCurMin() const;
inline double getHipAccum() const;
- virtual int getHllByteArrBytes() const = 0;
+ virtual uint32_t getHllByteArrBytes() const = 0;
- virtual int getUpdatableSerializationBytes() const;
- virtual int getCompactSerializationBytes() const;
+ virtual uint32_t getUpdatableSerializationBytes() const;
+ virtual uint32_t getCompactSerializationBytes() const;
virtual bool isOutOfOrderFlag() const;
virtual bool isEmpty() const;
@@ -74,19 +74,19 @@
inline double getKxQ0() const;
inline double getKxQ1() const;
- virtual int getMemDataStart() const;
- virtual int getPreInts() const;
+ virtual uint32_t getMemDataStart() const;
+ virtual uint8_t getPreInts() const;
- void putCurMin(int curMin);
+ void putCurMin(uint8_t curMin);
void putHipAccum(double hipAccum);
inline void putKxQ0(double kxq0);
inline void putKxQ1(double kxq1);
- void putNumAtCurMin(int numAtCurMin);
+ void putNumAtCurMin(uint32_t numAtCurMin);
- static int hllArrBytes(target_hll_type tgtHllType, int lgConfigK);
- static int hll4ArrBytes(int lgConfigK);
- static int hll6ArrBytes(int lgConfigK);
- static int hll8ArrBytes(int lgConfigK);
+ static uint32_t hllArrBytes(target_hll_type tgtHllType, uint8_t lgConfigK);
+ static uint32_t hll4ArrBytes(uint8_t lgConfigK);
+ static uint32_t hll6ArrBytes(uint8_t lgConfigK);
+ static uint32_t hll8ArrBytes(uint8_t lgConfigK);
virtual AuxHashMap<A>* getAuxHashMap() const;
@@ -98,16 +98,16 @@
protected:
void hipAndKxQIncrementalUpdate(uint8_t oldValue, uint8_t newValue);
- double getHllBitMapEstimate(int lgConfigK, int curMin, int numAtCurMin) const;
- double getHllRawEstimate(int lgConfigK, double kxqSum) const;
+ double getHllBitMapEstimate() const;
+ double getHllRawEstimate() const;
- double hipAccum;
- double kxq0;
- double kxq1;
- vector_u8<A> hllByteArr; //init by sub-classes
- int curMin; //always zero for Hll6 and Hll8, only tracked by Hll4Array
- int numAtCurMin; //interpreted as num zeros when curMin == 0
- bool oooFlag; //Out-Of-Order Flag
+ double hipAccum_;
+ double kxq0_;
+ double kxq1_;
+ vector_u8<A> hllByteArr_; //init by sub-classes
+ uint8_t curMin_; //always zero for Hll6 and Hll8, only tracked by Hll4Array
+ uint32_t numAtCurMin_; //interpreted as num zeros when curMin == 0
+ bool oooFlag_; //Out-Of-Order Flag
friend class HllSketchImplFactory<A>;
};
@@ -115,20 +115,20 @@
template<typename A>
class HllArray<A>::const_iterator: public std::iterator<std::input_iterator_tag, uint32_t> {
public:
- const_iterator(const uint8_t* array, size_t array_slze, size_t index, target_hll_type hll_type, const AuxHashMap<A>* exceptions, uint8_t offset, bool all);
+ const_iterator(const uint8_t* array, uint32_t array_slze, uint32_t index, target_hll_type hll_type, const AuxHashMap<A>* exceptions, uint8_t offset, bool all);
const_iterator& operator++();
bool operator!=(const const_iterator& other) const;
uint32_t operator*() const;
private:
- const uint8_t* array;
- size_t array_size;
- size_t index;
- target_hll_type hll_type;
- const AuxHashMap<A>* exceptions;
- uint8_t offset;
- bool all;
- uint8_t value; // cached value to avoid computing in operator++ and in operator*()
- static inline uint8_t get_value(const uint8_t* array, size_t index, target_hll_type hll_type, const AuxHashMap<A>* exceptions, uint8_t offset);
+ const uint8_t* array_;
+ uint32_t array_size_;
+ uint32_t index_;
+ target_hll_type hll_type_;
+ const AuxHashMap<A>* exceptions_;
+ uint8_t offset_;
+ bool all_;
+ uint8_t value_; // cached value to avoid computing in operator++ and in operator*()
+ static inline uint8_t get_value(const uint8_t* array, uint32_t index, target_hll_type hll_type, const AuxHashMap<A>* exceptions, uint8_t offset);
};
}
diff --git a/hll/include/HllSketch-internal.hpp b/hll/include/HllSketch-internal.hpp
index 8f7d1f4..08f1c07 100644
--- a/hll/include/HllSketch-internal.hpp
+++ b/hll/include/HllSketch-internal.hpp
@@ -42,7 +42,7 @@
} longDoubleUnion;
template<typename A>
-hll_sketch_alloc<A>::hll_sketch_alloc(int lg_config_k, target_hll_type tgt_type, bool start_full_size, const A& allocator) {
+hll_sketch_alloc<A>::hll_sketch_alloc(uint8_t lg_config_k, target_hll_type tgt_type, bool start_full_size, const A& allocator) {
HllUtil<A>::checkLgK(lg_config_k);
if (start_full_size) {
sketch_impl = HllSketchImplFactory<A>::newHll(lg_config_k, tgt_type, start_full_size, allocator);
@@ -122,7 +122,7 @@
}
template<typename A>
-void hll_sketch_alloc<A>::update(const uint64_t datum) {
+void hll_sketch_alloc<A>::update(uint64_t datum) {
// no sign extension with 64 bits so no need to cast to signed value
HashState hashResult;
HllUtil<A>::hash(&datum, sizeof(uint64_t), DEFAULT_SEED, hashResult);
@@ -130,53 +130,53 @@
}
template<typename A>
-void hll_sketch_alloc<A>::update(const uint32_t datum) {
+void hll_sketch_alloc<A>::update(uint32_t datum) {
update(static_cast<int32_t>(datum));
}
template<typename A>
-void hll_sketch_alloc<A>::update(const uint16_t datum) {
+void hll_sketch_alloc<A>::update(uint16_t datum) {
update(static_cast<int16_t>(datum));
}
template<typename A>
-void hll_sketch_alloc<A>::update(const uint8_t datum) {
+void hll_sketch_alloc<A>::update(uint8_t datum) {
update(static_cast<int8_t>(datum));
}
template<typename A>
-void hll_sketch_alloc<A>::update(const int64_t datum) {
+void hll_sketch_alloc<A>::update(int64_t datum) {
HashState hashResult;
HllUtil<A>::hash(&datum, sizeof(int64_t), DEFAULT_SEED, hashResult);
coupon_update(HllUtil<A>::coupon(hashResult));
}
template<typename A>
-void hll_sketch_alloc<A>::update(const int32_t datum) {
- int64_t val = static_cast<int64_t>(datum);
+void hll_sketch_alloc<A>::update(int32_t datum) {
+ const int64_t val = static_cast<int64_t>(datum);
HashState hashResult;
HllUtil<A>::hash(&val, sizeof(int64_t), DEFAULT_SEED, hashResult);
coupon_update(HllUtil<A>::coupon(hashResult));
}
template<typename A>
-void hll_sketch_alloc<A>::update(const int16_t datum) {
- int64_t val = static_cast<int64_t>(datum);
+void hll_sketch_alloc<A>::update(int16_t datum) {
+ const int64_t val = static_cast<int64_t>(datum);
HashState hashResult;
HllUtil<A>::hash(&val, sizeof(int64_t), DEFAULT_SEED, hashResult);
coupon_update(HllUtil<A>::coupon(hashResult));
}
template<typename A>
-void hll_sketch_alloc<A>::update(const int8_t datum) {
- int64_t val = static_cast<int64_t>(datum);
+void hll_sketch_alloc<A>::update(int8_t datum) {
+ const int64_t val = static_cast<int64_t>(datum);
HashState hashResult;
HllUtil<A>::hash(&val, sizeof(int64_t), DEFAULT_SEED, hashResult);
coupon_update(HllUtil<A>::coupon(hashResult));
}
template<typename A>
-void hll_sketch_alloc<A>::update(const double datum) {
+void hll_sketch_alloc<A>::update(double datum) {
longDoubleUnion d;
d.doubleBytes = static_cast<double>(datum);
if (datum == 0.0) {
@@ -190,7 +190,7 @@
}
template<typename A>
-void hll_sketch_alloc<A>::update(const float datum) {
+void hll_sketch_alloc<A>::update(float datum) {
longDoubleUnion d;
d.doubleBytes = static_cast<double>(datum);
if (datum == 0.0) {
@@ -204,7 +204,7 @@
}
template<typename A>
-void hll_sketch_alloc<A>::update(const void* data, const size_t lengthBytes) {
+void hll_sketch_alloc<A>::update(const void* data, size_t lengthBytes) {
if (data == nullptr) { return; }
HashState hashResult;
HllUtil<A>::hash(data, lengthBytes, DEFAULT_SEED, hashResult);
@@ -212,7 +212,7 @@
}
template<typename A>
-void hll_sketch_alloc<A>::coupon_update(int coupon) {
+void hll_sketch_alloc<A>::coupon_update(uint32_t coupon) {
if (coupon == HllUtil<A>::EMPTY) { return; }
HllSketchImpl<A>* result = this->sketch_impl->couponUpdate(coupon);
if (result != this->sketch_impl) {
@@ -352,12 +352,12 @@
}
template<typename A>
-double hll_sketch_alloc<A>::get_lower_bound(int numStdDev) const {
+double hll_sketch_alloc<A>::get_lower_bound(uint8_t numStdDev) const {
return sketch_impl->getLowerBound(numStdDev);
}
template<typename A>
-double hll_sketch_alloc<A>::get_upper_bound(int numStdDev) const {
+double hll_sketch_alloc<A>::get_upper_bound(uint8_t numStdDev) const {
return sketch_impl->getUpperBound(numStdDev);
}
@@ -367,7 +367,7 @@
}
template<typename A>
-int hll_sketch_alloc<A>::get_lg_config_k() const {
+uint8_t hll_sketch_alloc<A>::get_lg_config_k() const {
return sketch_impl->getLgConfigK();
}
@@ -387,12 +387,12 @@
}
template<typename A>
-int hll_sketch_alloc<A>::get_updatable_serialization_bytes() const {
+uint32_t hll_sketch_alloc<A>::get_updatable_serialization_bytes() const {
return sketch_impl->getUpdatableSerializationBytes();
}
template<typename A>
-int hll_sketch_alloc<A>::get_compact_serialization_bytes() const {
+uint32_t hll_sketch_alloc<A>::get_compact_serialization_bytes() const {
return sketch_impl->getCompactSerializationBytes();
}
@@ -435,11 +435,11 @@
}
template<typename A>
-int hll_sketch_alloc<A>::get_max_updatable_serialization_bytes(const int lg_config_k,
+uint32_t hll_sketch_alloc<A>::get_max_updatable_serialization_bytes(uint8_t lg_config_k,
const target_hll_type tgtHllType) {
- int arrBytes;
+ uint32_t arrBytes;
if (tgtHllType == target_hll_type::HLL_4) {
- const int auxBytes = 4 << HllUtil<A>::LG_AUX_ARR_INTS[lg_config_k];
+ const uint32_t auxBytes = 4 << HllUtil<A>::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);
@@ -450,8 +450,8 @@
}
template<typename A>
-double hll_sketch_alloc<A>::get_rel_err(const bool upperBound, const bool unioned,
- const int lg_config_k, const int numStdDev) {
+double hll_sketch_alloc<A>::get_rel_err(bool upperBound, bool unioned,
+ uint8_t lg_config_k, uint8_t numStdDev) {
return HllUtil<A>::getRelErr(upperBound, unioned, lg_config_k, numStdDev);
}
diff --git a/hll/include/HllSketchImpl-internal.hpp b/hll/include/HllSketchImpl-internal.hpp
index a280fd0..5db7965 100644
--- a/hll/include/HllSketchImpl-internal.hpp
+++ b/hll/include/HllSketchImpl-internal.hpp
@@ -26,12 +26,12 @@
namespace datasketches {
template<typename A>
-HllSketchImpl<A>::HllSketchImpl(const int lgConfigK, const target_hll_type tgtHllType,
- const hll_mode mode, const bool startFullSize)
- : lgConfigK(lgConfigK),
- tgtHllType(tgtHllType),
- mode(mode),
- startFullSize(startFullSize)
+HllSketchImpl<A>::HllSketchImpl(uint8_t lgConfigK, target_hll_type tgtHllType,
+ hll_mode mode, bool startFullSize)
+ : lgConfigK_(lgConfigK),
+ tgtHllType_(tgtHllType),
+ mode_(mode),
+ startFullSize_(startFullSize)
{
}
@@ -40,7 +40,7 @@
}
template<typename A>
-target_hll_type HllSketchImpl<A>::extractTgtHllType(const uint8_t modeByte) {
+target_hll_type HllSketchImpl<A>::extractTgtHllType(uint8_t modeByte) {
switch ((modeByte >> 2) & 0x3) {
case 0:
return target_hll_type::HLL_4;
@@ -54,7 +54,7 @@
}
template<typename A>
-hll_mode HllSketchImpl<A>::extractCurMode(const uint8_t modeByte) {
+hll_mode HllSketchImpl<A>::extractCurMode(uint8_t modeByte) {
switch (modeByte & 0x3) {
case 0:
return hll_mode::LIST;
@@ -68,12 +68,12 @@
}
template<typename A>
-uint8_t HllSketchImpl<A>::makeFlagsByte(const bool compact) const {
- uint8_t flags(0);
+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 |= (startFullSize_ ? HllUtil<A>::FULL_SIZE_FLAG_MASK : 0);
return flags;
}
@@ -92,7 +92,7 @@
uint8_t HllSketchImpl<A>::makeModeByte() const {
uint8_t byte = 0;
- switch (mode) {
+ switch (mode_) {
case LIST:
byte = 0;
break;
@@ -104,7 +104,7 @@
break;
}
- switch (tgtHllType) {
+ switch (tgtHllType_) {
case HLL_4:
byte |= (0 << 2); // for completeness
break;
@@ -121,27 +121,27 @@
template<typename A>
HllSketchImpl<A>* HllSketchImpl<A>::reset() {
- return HllSketchImplFactory<A>::reset(this, startFullSize);
+ return HllSketchImplFactory<A>::reset(this, startFullSize_);
}
template<typename A>
target_hll_type HllSketchImpl<A>::getTgtHllType() const {
- return tgtHllType;
+ return tgtHllType_;
}
template<typename A>
-int HllSketchImpl<A>::getLgConfigK() const {
- return lgConfigK;
+uint8_t HllSketchImpl<A>::getLgConfigK() const {
+ return lgConfigK_;
}
template<typename A>
hll_mode HllSketchImpl<A>::getCurMode() const {
- return mode;
+ return mode_;
}
template<typename A>
bool HllSketchImpl<A>::isStartFullSize() const {
- return startFullSize;
+ return startFullSize_;
}
}
diff --git a/hll/include/HllSketchImpl.hpp b/hll/include/HllSketchImpl.hpp
index 9f53705..e437c21 100644
--- a/hll/include/HllSketchImpl.hpp
+++ b/hll/include/HllSketchImpl.hpp
@@ -30,7 +30,7 @@
template<typename A>
class HllSketchImpl {
public:
- HllSketchImpl(int lgConfigK, target_hll_type tgtHllType, hll_mode mode, bool startFullSize);
+ HllSketchImpl(uint8_t lgConfigK, target_hll_type tgtHllType, hll_mode mode, bool startFullSize);
virtual ~HllSketchImpl();
virtual void serialize(std::ostream& os, bool compact) const = 0;
@@ -42,25 +42,25 @@
virtual std::function<void(HllSketchImpl<A>*)> get_deleter() const = 0;
- virtual HllSketchImpl* couponUpdate(int coupon) = 0;
+ virtual HllSketchImpl* couponUpdate(uint32_t coupon) = 0;
hll_mode getCurMode() const;
virtual double getEstimate() const = 0;
virtual double getCompositeEstimate() const = 0;
- virtual double getUpperBound(int numStdDev) const = 0;
- virtual double getLowerBound(int numStdDev) const = 0;
+ virtual double getUpperBound(uint8_t numStdDev) const = 0;
+ virtual double getLowerBound(uint8_t numStdDev) const = 0;
- inline int getLgConfigK() const;
+ inline uint8_t getLgConfigK() const;
- virtual int getMemDataStart() const = 0;
+ virtual uint32_t getMemDataStart() const = 0;
- virtual int getPreInts() const = 0;
+ virtual uint8_t getPreInts() const = 0;
target_hll_type getTgtHllType() const;
- virtual int getUpdatableSerializationBytes() const = 0;
- virtual int getCompactSerializationBytes() const = 0;
+ virtual uint32_t getUpdatableSerializationBytes() const = 0;
+ virtual uint32_t getCompactSerializationBytes() const = 0;
virtual bool isCompact() const = 0;
virtual bool isEmpty() const = 0;
@@ -75,10 +75,10 @@
uint8_t makeFlagsByte(bool compact) const;
uint8_t makeModeByte() const;
- const int lgConfigK;
- const target_hll_type tgtHllType;
- const hll_mode mode;
- const bool startFullSize;
+ const uint8_t lgConfigK_;
+ const target_hll_type tgtHllType_;
+ const hll_mode mode_;
+ const bool startFullSize_;
};
}
diff --git a/hll/include/HllSketchImplFactory.hpp b/hll/include/HllSketchImplFactory.hpp
index 85f9618..5baa656 100644
--- a/hll/include/HllSketchImplFactory.hpp
+++ b/hll/include/HllSketchImplFactory.hpp
@@ -39,7 +39,7 @@
static CouponHashSet<A>* promoteListToSet(const CouponList<A>& list);
static HllArray<A>* promoteListOrSetToHll(const CouponList<A>& list);
- static HllArray<A>* newHll(int lgConfigK, target_hll_type tgtHllType, bool startFullSize, const A& allocator);
+ static HllArray<A>* newHll(uint8_t lgConfigK, target_hll_type tgtHllType, bool startFullSize, const A& allocator);
// resets the input impl, deleting the input pointer and returning a new pointer
static HllSketchImpl<A>* reset(HllSketchImpl<A>* impl, bool startFullSize);
@@ -53,7 +53,7 @@
CouponHashSet<A>* HllSketchImplFactory<A>::promoteListToSet(const CouponList<A>& list) {
using ChsAlloc = typename std::allocator_traits<A>::template rebind_alloc<CouponHashSet<A>>;
CouponHashSet<A>* chSet = new (ChsAlloc(list.getAllocator()).allocate(1)) CouponHashSet<A>(list.getLgConfigK(), list.getTgtHllType(), list.getAllocator());
- for (auto coupon: list) {
+ for (const auto coupon: list) {
chSet->couponUpdate(coupon);
}
return chSet;
@@ -63,7 +63,7 @@
HllArray<A>* HllSketchImplFactory<A>::promoteListOrSetToHll(const CouponList<A>& src) {
HllArray<A>* tgtHllArr = HllSketchImplFactory<A>::newHll(src.getLgConfigK(), src.getTgtHllType(), false, src.getAllocator());
tgtHllArr->putKxQ0(1 << src.getLgConfigK());
- for (auto coupon: src) {
+ for (const auto coupon: src) {
tgtHllArr->couponUpdate(coupon);
}
tgtHllArr->putHipAccum(src.getEstimate());
@@ -75,7 +75,7 @@
HllSketchImpl<A>* HllSketchImplFactory<A>::deserialize(std::istream& is, const A& allocator) {
// 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 int preInts = is.peek();
+ const uint8_t preInts = static_cast<uint8_t>(is.peek());
if (preInts == HllUtil<A>::HLL_PREINTS) {
return HllArray<A>::newHll(is, allocator);
} else if (preInts == HllUtil<A>::HASH_SET_PREINTS) {
@@ -90,7 +90,7 @@
template<typename A>
HllSketchImpl<A>* HllSketchImplFactory<A>::deserialize(const void* bytes, size_t len, const A& allocator) {
// read current mode directly
- const int preInts = static_cast<const uint8_t*>(bytes)[0];
+ const uint8_t preInts = static_cast<const uint8_t*>(bytes)[0];
if (preInts == HllUtil<A>::HLL_PREINTS) {
return HllArray<A>::newHll(bytes, len, allocator);
} else if (preInts == HllUtil<A>::HASH_SET_PREINTS) {
@@ -103,7 +103,7 @@
}
template<typename A>
-HllArray<A>* HllSketchImplFactory<A>::newHll(int lgConfigK, target_hll_type tgtHllType, bool startFullSize, const A& allocator) {
+HllArray<A>* HllSketchImplFactory<A>::newHll(uint8_t lgConfigK, target_hll_type tgtHllType, bool startFullSize, const A& allocator) {
switch (tgtHllType) {
case HLL_8:
using Hll8Alloc = typename std::allocator_traits<A>::template rebind_alloc<Hll8Array<A>>;
@@ -134,7 +134,7 @@
template<typename A>
Hll4Array<A>* HllSketchImplFactory<A>::convertToHll4(const HllArray<A>& srcHllArr) {
- const int lgConfigK = srcHllArr.getLgConfigK();
+ const uint8_t lgConfigK = srcHllArr.getLgConfigK();
using Hll4Alloc = typename std::allocator_traits<A>::template rebind_alloc<Hll4Array<A>>;
Hll4Array<A>* hll4Array = new (Hll4Alloc(srcHllArr.getAllocator()).allocate(1))
Hll4Array<A>(lgConfigK, srcHllArr.isStartFullSize(), srcHllArr.getAllocator());
@@ -146,7 +146,7 @@
template<typename A>
Hll6Array<A>* HllSketchImplFactory<A>::convertToHll6(const HllArray<A>& srcHllArr) {
- const int lgConfigK = srcHllArr.getLgConfigK();
+ const uint8_t lgConfigK = srcHllArr.getLgConfigK();
using Hll6Alloc = typename std::allocator_traits<A>::template rebind_alloc<Hll6Array<A>>;
Hll6Array<A>* hll6Array = new (Hll6Alloc(srcHllArr.getAllocator()).allocate(1))
Hll6Array<A>(lgConfigK, srcHllArr.isStartFullSize(), srcHllArr.getAllocator());
@@ -158,7 +158,7 @@
template<typename A>
Hll8Array<A>* HllSketchImplFactory<A>::convertToHll8(const HllArray<A>& srcHllArr) {
- const int lgConfigK = srcHllArr.getLgConfigK();
+ const uint8_t lgConfigK = srcHllArr.getLgConfigK();
using Hll8Alloc = typename std::allocator_traits<A>::template rebind_alloc<Hll8Array<A>>;
Hll8Array<A>* hll8Array = new (Hll8Alloc(srcHllArr.getAllocator()).allocate(1))
Hll8Array<A>(lgConfigK, srcHllArr.isStartFullSize(), srcHllArr.getAllocator());
diff --git a/hll/include/HllUnion-internal.hpp b/hll/include/HllUnion-internal.hpp
index 716fab6..db6402f 100644
--- a/hll/include/HllUnion-internal.hpp
+++ b/hll/include/HllUnion-internal.hpp
@@ -32,151 +32,151 @@
namespace datasketches {
template<typename A>
-hll_union_alloc<A>::hll_union_alloc(const int lg_max_k, const A& allocator):
- lg_max_k(HllUtil<A>::checkLgK(lg_max_k)),
- gadget(lg_max_k, target_hll_type::HLL_8, false, allocator)
+hll_union_alloc<A>::hll_union_alloc(uint8_t lg_max_k, const A& allocator):
+ lg_max_k_(HllUtil<A>::checkLgK(lg_max_k)),
+ gadget_(lg_max_k, target_hll_type::HLL_8, false, allocator)
{}
template<typename A>
hll_sketch_alloc<A> hll_union_alloc<A>::get_result(target_hll_type target_type) const {
- return hll_sketch_alloc<A>(gadget, target_type);
+ return hll_sketch_alloc<A>(gadget_, target_type);
}
template<typename A>
void hll_union_alloc<A>::update(const hll_sketch_alloc<A>& sketch) {
if (sketch.is_empty()) return;
- union_impl(sketch, lg_max_k);
+ union_impl(sketch, lg_max_k_);
}
template<typename A>
void hll_union_alloc<A>::update(hll_sketch_alloc<A>&& sketch) {
if (sketch.is_empty()) return;
- if (gadget.is_empty() && sketch.get_target_type() == HLL_8 && sketch.get_lg_config_k() <= lg_max_k) {
- if (sketch.get_current_mode() == HLL || sketch.get_lg_config_k() == lg_max_k) {
- gadget = std::move(sketch);
+ if (gadget_.is_empty() && sketch.get_target_type() == HLL_8 && sketch.get_lg_config_k() <= lg_max_k_) {
+ if (sketch.get_current_mode() == HLL || sketch.get_lg_config_k() == lg_max_k_) {
+ gadget_ = std::move(sketch);
}
}
- union_impl(sketch, lg_max_k);
+ union_impl(sketch, lg_max_k_);
}
template<typename A>
void hll_union_alloc<A>::update(const std::string& datum) {
- gadget.update(datum);
+ gadget_.update(datum);
}
template<typename A>
void hll_union_alloc<A>::update(const uint64_t datum) {
- gadget.update(datum);
+ gadget_.update(datum);
}
template<typename A>
-void hll_union_alloc<A>::update(const uint32_t datum) {
- gadget.update(datum);
+void hll_union_alloc<A>::update(uint32_t datum) {
+ gadget_.update(datum);
}
template<typename A>
-void hll_union_alloc<A>::update(const uint16_t datum) {
- gadget.update(datum);
+void hll_union_alloc<A>::update(uint16_t datum) {
+ gadget_.update(datum);
}
template<typename A>
-void hll_union_alloc<A>::update(const uint8_t datum) {
- gadget.update(datum);
+void hll_union_alloc<A>::update(uint8_t datum) {
+ gadget_.update(datum);
}
template<typename A>
-void hll_union_alloc<A>::update(const int64_t datum) {
- gadget.update(datum);
+void hll_union_alloc<A>::update(int64_t datum) {
+ gadget_.update(datum);
}
template<typename A>
-void hll_union_alloc<A>::update(const int32_t datum) {
- gadget.update(datum);
+void hll_union_alloc<A>::update(int32_t datum) {
+ gadget_.update(datum);
}
template<typename A>
-void hll_union_alloc<A>::update(const int16_t datum) {
- gadget.update(datum);
+void hll_union_alloc<A>::update(int16_t datum) {
+ gadget_.update(datum);
}
template<typename A>
-void hll_union_alloc<A>::update(const int8_t datum) {
- gadget.update(datum);
+void hll_union_alloc<A>::update(int8_t datum) {
+ gadget_.update(datum);
}
template<typename A>
-void hll_union_alloc<A>::update(const double datum) {
- gadget.update(datum);
+void hll_union_alloc<A>::update(double datum) {
+ gadget_.update(datum);
}
template<typename A>
-void hll_union_alloc<A>::update(const float datum) {
- gadget.update(datum);
+void hll_union_alloc<A>::update(float datum) {
+ gadget_.update(datum);
}
template<typename A>
-void hll_union_alloc<A>::update(const void* data, const size_t length_bytes) {
- gadget.update(data, length_bytes);
+void hll_union_alloc<A>::update(const void* data, size_t length_bytes) {
+ gadget_.update(data, length_bytes);
}
template<typename A>
-void hll_union_alloc<A>::coupon_update(const int coupon) {
+void hll_union_alloc<A>::coupon_update(uint32_t coupon) {
if (coupon == HllUtil<A>::EMPTY) { return; }
- HllSketchImpl<A>* result = gadget.sketch_impl->coupon_update(coupon);
- if (result != gadget.sketch_impl) {
- if (gadget.sketch_impl != nullptr) { gadget.sketch_impl->get_deleter()(gadget.sketch_impl); }
- gadget.sketch_impl = result;
+ HllSketchImpl<A>* result = gadget_.sketch_impl->coupon_update(coupon);
+ if (result != gadget_.sketch_impl) {
+ if (gadget_.sketch_impl != nullptr) { gadget_.sketch_impl->get_deleter()(gadget_.sketch_impl); }
+ gadget_.sketch_impl = result;
}
}
template<typename A>
double hll_union_alloc<A>::get_estimate() const {
- return gadget.get_estimate();
+ return gadget_.get_estimate();
}
template<typename A>
double hll_union_alloc<A>::get_composite_estimate() const {
- return gadget.get_composite_estimate();
+ return gadget_.get_composite_estimate();
}
template<typename A>
-double hll_union_alloc<A>::get_lower_bound(const int num_std_dev) const {
- return gadget.get_lower_bound(num_std_dev);
+double hll_union_alloc<A>::get_lower_bound(uint8_t num_std_dev) const {
+ return gadget_.get_lower_bound(num_std_dev);
}
template<typename A>
-double hll_union_alloc<A>::get_upper_bound(const int num_std_dev) const {
+double hll_union_alloc<A>::get_upper_bound(uint8_t num_std_dev) const {
return gadget.get_upper_bound(num_std_dev);
}
template<typename A>
-int hll_union_alloc<A>::get_lg_config_k() const {
- return gadget.get_lg_config_k();
+uint8_t hll_union_alloc<A>::get_lg_config_k() const {
+ return gadget_.get_lg_config_k();
}
template<typename A>
void hll_union_alloc<A>::reset() {
- gadget.reset();
+ gadget_.reset();
}
template<typename A>
bool hll_union_alloc<A>::is_empty() const {
- return gadget.is_empty();
+ return gadget_.is_empty();
}
template<typename A>
bool hll_union_alloc<A>::is_out_of_order_flag() const {
- return gadget.is_out_of_order_flag();
+ return gadget_.is_out_of_order_flag();
}
template<typename A>
hll_mode hll_union_alloc<A>::get_current_mode() const {
- return gadget.get_current_mode();
+ return gadget_.get_current_mode();
}
template<typename A>
bool hll_union_alloc<A>::is_estimation_mode() const {
- return gadget.is_estimation_mode();
+ return gadget_.is_estimation_mode();
}
template<typename A>
@@ -185,13 +185,13 @@
}
template<typename A>
-double hll_union_alloc<A>::get_rel_err(const bool upper_bound, const bool unioned,
- const int lg_config_k, const int num_std_dev) {
+double hll_union_alloc<A>::get_rel_err(bool upper_bound, bool unioned,
+ uint8_t lg_config_k, uint8_t num_std_dev) {
return HllUtil<A>::getRelErr(upper_bound, unioned, lg_config_k, num_std_dev);
}
template<typename A>
-HllSketchImpl<A>* hll_union_alloc<A>::copy_or_downsample(const HllSketchImpl<A>* src_impl, const int tgt_lg_k) {
+HllSketchImpl<A>* hll_union_alloc<A>::copy_or_downsample(const HllSketchImpl<A>* src_impl, uint8_t tgt_lg_k) {
if (src_impl->getCurMode() != HLL) {
throw std::logic_error("Attempt to downsample non-HLL sketch");
}
@@ -210,7 +210,7 @@
}
template<typename A>
-inline HllSketchImpl<A>* hll_union_alloc<A>::leak_free_coupon_update(HllSketchImpl<A>* impl, const int coupon) {
+inline HllSketchImpl<A>* hll_union_alloc<A>::leak_free_coupon_update(HllSketchImpl<A>* impl, uint32_t coupon) {
HllSketchImpl<A>* result = impl->couponUpdate(coupon);
if (result != impl) {
impl->get_deleter()(impl);
@@ -219,13 +219,13 @@
}
template<typename A>
-void hll_union_alloc<A>::union_impl(const hll_sketch_alloc<A>& sketch, const int lg_max_k) {
+void hll_union_alloc<A>::union_impl(const hll_sketch_alloc<A>& sketch, uint8_t lg_max_k) {
const HllSketchImpl<A>* src_impl = sketch.sketch_impl; //default
- HllSketchImpl<A>* dst_impl = gadget.sketch_impl; //default
+ HllSketchImpl<A>* dst_impl = gadget_.sketch_impl; //default
if (src_impl->getCurMode() == LIST || src_impl->getCurMode() == SET) {
if (dst_impl->isEmpty() && src_impl->getLgConfigK() == dst_impl->getLgConfigK()) {
dst_impl = src_impl->copyAs(HLL_8);
- gadget.sketch_impl->get_deleter()(gadget.sketch_impl); // gadget to be replaced
+ gadget_.sketch_impl->get_deleter()(gadget_.sketch_impl); // gadget to be replaced
} else {
const CouponList<A>* src = static_cast<const CouponList<A>*>(src_impl);
for (auto coupon: *src) {
@@ -239,11 +239,11 @@
const CouponList<A>* src = static_cast<const CouponList<A>*>(dst_impl);
dst_impl = copy_or_downsample(src_impl, lg_max_k);
static_cast<Hll8Array<A>*>(dst_impl)->mergeList(*src);
- gadget.sketch_impl->get_deleter()(gadget.sketch_impl); // gadget to be replaced
+ gadget_.sketch_impl->get_deleter()(gadget_.sketch_impl); // gadget to be replaced
} else { // gadget is HLL
if (src_impl->getLgConfigK() < dst_impl->getLgConfigK()) {
dst_impl = copy_or_downsample(dst_impl, sketch.get_lg_config_k());
- gadget.sketch_impl->get_deleter()(gadget.sketch_impl); // gadget to be replaced
+ gadget_.sketch_impl->get_deleter()(gadget_.sketch_impl); // gadget to be replaced
}
const HllArray<A>* src = static_cast<const HllArray<A>*>(src_impl);
static_cast<Hll8Array<A>*>(dst_impl)->mergeHll(*src);
@@ -252,9 +252,9 @@
}
} else { // src is HLL, gadget is empty
dst_impl = copy_or_downsample(src_impl, lg_max_k);
- gadget.sketch_impl->get_deleter()(gadget.sketch_impl); // gadget to be replaced
+ gadget_.sketch_impl->get_deleter()(gadget_.sketch_impl); // gadget to be replaced
}
- gadget.sketch_impl = dst_impl; // gadget replaced
+ gadget_.sketch_impl = dst_impl; // gadget replaced
}
}
diff --git a/hll/include/HllUtil.hpp b/hll/include/HllUtil.hpp
index 3a1ebe2..76e9ac9 100644
--- a/hll/include/HllUtil.hpp
+++ b/hll/include/HllUtil.hpp
@@ -40,86 +40,85 @@
class HllUtil final {
public:
// preamble stuff
- static const int SER_VER = 1;
- static const int FAMILY_ID = 7;
+ static const uint8_t SER_VER = 1;
+ static const uint8_t FAMILY_ID = 7;
- static const int EMPTY_FLAG_MASK = 4;
- static const int COMPACT_FLAG_MASK = 8;
- static const int OUT_OF_ORDER_FLAG_MASK = 16;
- static const int FULL_SIZE_FLAG_MASK = 32;
+ 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 int PREAMBLE_INTS_BYTE = 0;
- static const int SER_VER_BYTE = 1;
- static const int FAMILY_BYTE = 2;
- static const int LG_K_BYTE = 3;
- static const int LG_ARR_BYTE = 4;
- static const int FLAGS_BYTE = 5;
- static const int LIST_COUNT_BYTE = 6;
- static const int HLL_CUR_MIN_BYTE = 6;
- static const int MODE_BYTE = 7; // lo2bits = curMode, next 2 bits = tgtHllMode
+ 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 int LIST_INT_ARR_START = 8;
- static const int LIST_PREINTS = 2;
+ static const uint32_t LIST_INT_ARR_START = 8;
+ static const uint8_t LIST_PREINTS = 2;
// Coupon Hash Set
- static const int HASH_SET_COUNT_INT = 8;
- static const int HASH_SET_INT_ARR_START = 12;
- static const int HASH_SET_PREINTS = 3;
+ 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 int HLL_PREINTS = 10;
- static const int HLL_BYTE_ARR_START = 40;
- static const int HIP_ACCUM_DOUBLE = 8;
- static const int KXQ0_DOUBLE = 16;
- static const int KXQ1_DOUBLE = 24;
- static const int CUR_MIN_COUNT_INT = 32;
- static const int AUX_COUNT_INT = 36;
+ 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 int EMPTY_SKETCH_SIZE_BYTES = 8;
+ static const uint32_t EMPTY_SKETCH_SIZE_BYTES = 8;
// other HllUtil stuff
- static const int KEY_BITS_26 = 26;
- static const int VAL_BITS_6 = 6;
- static const int KEY_MASK_26 = (1 << KEY_BITS_26) - 1;
- static const int VAL_MASK_6 = (1 << VAL_BITS_6) - 1;
- static const int EMPTY = 0;
- static const int MIN_LOG_K = 4;
- static const int MAX_LOG_K = 21;
+ 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 int LG_INIT_LIST_SIZE = 3;
- static const int LG_INIT_SET_SIZE = 5;
- static const int RESIZE_NUMER = 3;
- static const int RESIZE_DENOM = 4;
+ 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 int loNibbleMask = 0x0f;
- static const int hiNibbleMask = 0xf0;
- static const int AUX_TOKEN = 0xf;
+ 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 int LG_AUX_ARR_INTS[];
+ static const uint8_t LG_AUX_ARR_INTS[];
- static int coupon(const uint64_t hash[]);
- static int coupon(const HashState& hashState);
- static void hash(const void* key, int keyLen, uint64_t seed, HashState& result);
- static int checkLgK(int lgK);
+ static uint32_t coupon(const uint64_t hash[]);
+ static uint32_t coupon(const HashState& hashState);
+ static void hash(const void* key, size_t keyLen, uint64_t seed, HashState& result);
+ static uint8_t checkLgK(uint8_t lgK);
static void checkMemSize(uint64_t minBytes, uint64_t capBytes);
- static inline void checkNumStdDev(int numStdDev);
- static int pair(int slotNo, int value);
- static int getLow26(unsigned int coupon);
- static int getValue(unsigned int coupon);
- static double invPow2(int e);
- static unsigned int ceilingPowerOf2(unsigned int n);
- static unsigned int simpleIntLog2(unsigned int n); // n must be power of 2
- static int computeLgArrInts(hll_mode mode, int count, int lgConfigK);
- static double getRelErr(bool upperBound, bool unioned,
- int lgConfigK, int numStdDev);
+ static inline void checkNumStdDev(uint8_t numStdDev);
+ static uint32_t pair(uint32_t slotNo, uint8_t value);
+ static uint32_t getLow26(uint32_t coupon);
+ static uint8_t getValue(uint32_t coupon);
+ static double invPow2(uint8_t e);
+ static uint8_t ceilingPowerOf2(uint32_t n);
+ static uint8_t simpleIntLog2(uint32_t n); // n must be power of 2
+ static uint8_t computeLgArrInts(hll_mode mode, uint32_t count, uint8_t lgConfigK);
+ static double getRelErr(bool upperBound, bool unioned, uint8_t lgConfigK, uint8_t numStdDev);
};
template<typename A>
@@ -132,41 +131,41 @@
const double HllUtil<A>::COUPON_RSE = COUPON_RSE_FACTOR / (1 << 13);
template<typename A>
-const int HllUtil<A>::LG_AUX_ARR_INTS[] = {
+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 int HllUtil<A>::coupon(const uint64_t hash[]) {
- int addr26 = (int) (hash[0] & KEY_MASK_26);
- int lz = count_leading_zeros_in_u64(hash[1]);
- int value = ((lz > 62 ? 62 : lz) + 1);
+inline uint32_t HllUtil<A>::coupon(const uint64_t hash[]) {
+ uint32_t addr26 = hash[0] & 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;
}
template<typename A>
-inline int HllUtil<A>::coupon(const HashState& hashState) {
- int addr26 = (int) (hashState.h1 & KEY_MASK_26);
- int lz = count_leading_zeros_in_u64(hashState.h2);
- int value = ((lz > 62 ? 62 : lz) + 1);
+inline uint32_t HllUtil<A>::coupon(const HashState& hashState) {
+ uint32_t addr26 = (int) (hashState.h1 & 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;
}
template<typename A>
-inline void HllUtil<A>::hash(const void* key, const int keyLen, const uint64_t seed, HashState& result) {
+inline void HllUtil<A>::hash(const void* key, size_t keyLen, uint64_t seed, HashState& result) {
MurmurHash3_x64_128(key, keyLen, seed, result);
}
template<typename A>
-inline double HllUtil<A>::getRelErr(const bool upperBound, const bool unioned,
- const int lgConfigK, const int numStdDev) {
+inline double HllUtil<A>::getRelErr(bool upperBound, bool unioned,
+ uint8_t lgConfigK, uint8_t numStdDev) {
return RelativeErrorTables<A>::getRelErr(upperBound, unioned, lgConfigK, numStdDev);
}
template<typename A>
-inline int HllUtil<A>::checkLgK(const int lgK) {
+inline uint8_t HllUtil<A>::checkLgK(uint8_t lgK) {
if ((lgK >= HllUtil<A>::MIN_LOG_K) && (lgK <= HllUtil<A>::MAX_LOG_K)) {
return lgK;
} else {
@@ -175,36 +174,36 @@
}
template<typename A>
-inline void HllUtil<A>::checkMemSize(const uint64_t minBytes, const uint64_t capBytes) {
+inline void HllUtil<A>::checkMemSize(uint64_t minBytes, uint64_t capBytes) {
if (capBytes < minBytes) {
throw std::invalid_argument("Given destination array is not large enough: " + std::to_string(capBytes));
}
}
template<typename A>
-inline void HllUtil<A>::checkNumStdDev(const int numStdDev) {
+inline void HllUtil<A>::checkNumStdDev(uint8_t numStdDev) {
if ((numStdDev < 1) || (numStdDev > 3)) {
throw std::invalid_argument("NumStdDev may not be less than 1 or greater than 3.");
}
}
template<typename A>
-inline int HllUtil<A>::pair(const int slotNo, const int value) {
+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);
}
template<typename A>
-inline int HllUtil<A>::getLow26(const unsigned int coupon) {
+inline uint32_t HllUtil<A>::getLow26(uint32_t coupon) {
return coupon & HllUtil<A>::KEY_MASK_26;
}
template<typename A>
-inline int HllUtil<A>::getValue(const unsigned int coupon) {
+inline uint8_t HllUtil<A>::getValue(uint32_t coupon) {
return coupon >> HllUtil<A>::KEY_BITS_26;
}
template<typename A>
-inline double HllUtil<A>::invPow2(const int e) {
+inline double HllUtil<A>::invPow2(uint8_t e) {
union {
long long longVal;
double doubleVal;
@@ -214,7 +213,7 @@
}
template<typename A>
-inline uint32_t HllUtil<A>::simpleIntLog2(uint32_t n) {
+inline uint8_t HllUtil<A>::simpleIntLog2(uint32_t n) {
if (n == 0) {
throw std::logic_error("cannot take log of 0");
}
@@ -222,16 +221,16 @@
}
template<typename A>
-inline int HllUtil<A>::computeLgArrInts(hll_mode mode, int count, int lgConfigK) {
+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; }
- int ceilPwr2 = ceiling_power_of_2(count);
+ uint32_t ceilPwr2 = ceiling_power_of_2(count);
if ((HllUtil<A>::RESIZE_DENOM * count) > (HllUtil<A>::RESIZE_NUMER * ceilPwr2)) { ceilPwr2 <<= 1;}
if (mode == SET) {
- return fmax(HllUtil<A>::LG_INIT_SET_SIZE, HllUtil<A>::simpleIntLog2(ceilPwr2));
+ return std::max<uint8_t>(HllUtil<A>::LG_INIT_SET_SIZE, HllUtil<A>::simpleIntLog2(ceilPwr2));
}
//only used for HLL4
- return fmax(HllUtil<A>::LG_AUX_ARR_INTS[lgConfigK], HllUtil<A>::simpleIntLog2(ceilPwr2));
+ return std::max<uint8_t>(HllUtil<A>::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 35d0e0b..67e3733 100644
--- a/hll/include/coupon_iterator-internal.hpp
+++ b/hll/include/coupon_iterator-internal.hpp
@@ -25,30 +25,30 @@
namespace datasketches {
template<typename A>
-coupon_iterator<A>::coupon_iterator(const int* array, size_t array_size, size_t index, bool all):
-array(array), array_size(array_size), index(index), all(all) {
- while (this->index < array_size) {
- if (all || array[this->index] != HllUtil<A>::EMPTY) break;
- this->index++;
+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;
+ ++index_;
}
}
template<typename A>
coupon_iterator<A>& coupon_iterator<A>::operator++() {
- while (++index < array_size) {
- if (all || array[index] != HllUtil<A>::EMPTY) break;
+ while (++index_ < array_size_) {
+ if (all_ || array_[index_] != HllUtil<A>::EMPTY) break;
}
return *this;
}
template<typename A>
bool coupon_iterator<A>::operator!=(const coupon_iterator& other) const {
- return index != other.index;
+ return index_ != other.index_;
}
template<typename A>
uint32_t coupon_iterator<A>::operator*() const {
- return array[index];
+ return array_[index_];
}
}
diff --git a/hll/include/coupon_iterator.hpp b/hll/include/coupon_iterator.hpp
index 9f373cf..896a2f7 100644
--- a/hll/include/coupon_iterator.hpp
+++ b/hll/include/coupon_iterator.hpp
@@ -25,15 +25,15 @@
template<typename A>
class coupon_iterator: public std::iterator<std::input_iterator_tag, uint32_t> {
public:
- coupon_iterator(const int* array, size_t array_slze, size_t index, bool all);
+ coupon_iterator(const uint32_t* array, size_t array_slze, size_t index, bool all);
coupon_iterator& operator++();
bool operator!=(const coupon_iterator& other) const;
uint32_t operator*() const;
private:
- const int* array;
- size_t array_size;
- size_t index;
- bool all;
+ const uint32_t* array_;
+ size_t array_size_;
+ size_t index_;
+ bool all_;
};
}
diff --git a/hll/include/hll.hpp b/hll/include/hll.hpp
index a65b945..34193e5 100644
--- a/hll/include/hll.hpp
+++ b/hll/include/hll.hpp
@@ -119,7 +119,7 @@
* keeping memory use constant (if HLL_6 or HLL_8) at the cost of
* starting out using much more memory
*/
- explicit hll_sketch_alloc(int lg_config_k, target_hll_type tgt_type = HLL_4, bool start_full_size = false, const A& allocator = A());
+ explicit hll_sketch_alloc(uint8_t lg_config_k, target_hll_type tgt_type = HLL_4, bool start_full_size = false, const A& allocator = A());
/**
* Copy constructor
@@ -306,7 +306,7 @@
* @param num_std_dev Number of standard deviations, an integer from the set {1, 2, 3}.
* @return The approximate lower bound.
*/
- double get_lower_bound(int num_std_dev) const;
+ double get_lower_bound(uint8_t num_std_dev) const;
/**
* Returns the approximate upper error bound given the specified
@@ -314,13 +314,13 @@
* @param num_std_dev Number of standard deviations, an integer from the set {1, 2, 3}.
* @return The approximate upper bound.
*/
- double get_upper_bound(int num_std_dev) const;
+ double get_upper_bound(uint8_t num_std_dev) const;
/**
* Returns sketch's configured lg_k value.
* @return Configured lg_k value.
*/
- int get_lg_config_k() const;
+ uint8_t get_lg_config_k() const;
/**
* Returns the sketch's target HLL mode (from #target_hll_type).
@@ -344,13 +344,13 @@
* Returns the size of the sketch serialized in compact form.
* @return Size of the sketch serialized in compact form, in bytes.
*/
- int get_compact_serialization_bytes() const;
+ uint32_t get_compact_serialization_bytes() const;
/**
* Returns the size of the sketch serialized without compaction.
* @return Size of the sketch serialized without compaction, in bytes.
*/
- int get_updatable_serialization_bytes() const;
+ uint32_t get_updatable_serialization_bytes() const;
/**
* Returns the maximum size in bytes that this sketch can grow to
@@ -363,7 +363,7 @@
* @param tgt_type the desired Hll type
* @return the maximum size in bytes that this sketch can grow to.
*/
- static int get_max_updatable_serialization_bytes(int lg_k, target_hll_type tgt_type);
+ static uint32_t get_max_updatable_serialization_bytes(uint8_t lg_k, target_hll_type tgt_type);
/**
* Gets the current (approximate) Relative Error (RE) asymptotic values given several
@@ -376,18 +376,18 @@
* @return the current (approximate) RelativeError
*/
static double get_rel_err(bool upper_bound, bool unioned,
- int lg_config_k, int num_std_dev);
+ uint8_t lg_config_k, uint8_t num_std_dev);
private:
explicit hll_sketch_alloc(HllSketchImpl<A>* that);
- void coupon_update(int coupon);
+ void coupon_update(uint32_t coupon);
std::string type_as_string() const;
std::string mode_as_string() const;
hll_mode get_current_mode() const;
- int get_serialization_version() const;
+ uint8_t get_serialization_version() const;
bool is_out_of_order_flag() const;
bool is_estimation_mode() const;
@@ -431,7 +431,7 @@
* @param lg_max_k The maximum size, in log2, of k. The value must
* be between 7 and 21, inclusive.
*/
- explicit hll_union_alloc(int lg_max_k, const A& allocator = A());
+ explicit hll_union_alloc(uint8_t lg_max_k, const A& allocator = A());
/**
* Returns the current cardinality estimate
@@ -458,7 +458,7 @@
* @param num_std_dev Number of standard deviations, an integer from the set {1, 2, 3}.
* @return The approximate lower bound.
*/
- double get_lower_bound(int num_std_dev) const;
+ double get_lower_bound(uint8_t num_std_dev) const;
/**
* Returns the approximate upper error bound given the specified
@@ -466,13 +466,13 @@
* @param num_std_dev Number of standard deviations, an integer from the set {1, 2, 3}.
* @return The approximate upper bound.
*/
- double get_upper_bound(int num_std_dev) const;
+ double get_upper_bound(uint8_t num_std_dev) const;
/**
* Returns union's configured lg_k value.
* @return Configured lg_k value.
*/
- int get_lg_config_k() const;
+ uint8_t get_lg_config_k() const;
/**
* Returns the union's target HLL mode (from #target_hll_type).
@@ -598,7 +598,7 @@
* @return the current (approximate) RelativeError
*/
static double get_rel_err(bool upper_bound, bool unioned,
- int lg_config_k, int num_std_dev);
+ uint8_t lg_config_k, uint8_t num_std_dev);
private:
@@ -611,21 +611,21 @@
* @param incoming_impl the given incoming sketch, which may not be modified.
* @param lg_max_k the maximum value of log2 K for this union.
*/
- inline void union_impl(const hll_sketch_alloc<A>& sketch, int lg_max_k);
+ inline void union_impl(const hll_sketch_alloc<A>& sketch, uint8_t lg_max_k);
- static HllSketchImpl<A>* copy_or_downsample(const HllSketchImpl<A>* src_impl, int tgt_lg_k);
+ static HllSketchImpl<A>* copy_or_downsample(const HllSketchImpl<A>* src_impl, uint8_t tgt_lg_k);
- void coupon_update(int coupon);
+ void coupon_update(uint32_t coupon);
hll_mode get_current_mode() const;
bool is_out_of_order_flag() const;
bool is_estimation_mode() const;
// calls couponUpdate on sketch, freeing the old sketch upon changes in hll_mode
- static HllSketchImpl<A>* leak_free_coupon_update(HllSketchImpl<A>* impl, int coupon);
+ static HllSketchImpl<A>* leak_free_coupon_update(HllSketchImpl<A>* impl, uint32_t coupon);
- int lg_max_k;
- hll_sketch_alloc<A> gadget;
+ uint8_t lg_max_k_;
+ hll_sketch_alloc<A> gadget_;
};
/// convenience alias for hll_sketch with default allocator
diff --git a/hll/test/AuxHashMapTest.cpp b/hll/test/AuxHashMapTest.cpp
index ed1b380..a653059 100644
--- a/hll/test/AuxHashMapTest.cpp
+++ b/hll/test/AuxHashMapTest.cpp
@@ -45,7 +45,7 @@
AuxHashMap<std::allocator<uint8_t>>::make_deleter()
);
REQUIRE(map->getLgAuxArrInts() == 3);
- for (int i = 1; i <= 7; ++i) {
+ for (uint8_t i = 1; i <= 7; ++i) {
map->mustAdd(i, i);
}
REQUIRE(map->getLgAuxArrInts() == 4);
diff --git a/hll/test/CouponHashSetTest.cpp b/hll/test/CouponHashSetTest.cpp
index ebadd8f..599b528 100644
--- a/hll/test/CouponHashSetTest.cpp
+++ b/hll/test/CouponHashSetTest.cpp
@@ -30,7 +30,7 @@
namespace datasketches {
TEST_CASE("coupon hash set: check corrupt bytearray", "[coupon_hash_set]") {
- int lgK = 8;
+ uint8_t lgK = 8;
hll_sketch sk1(lgK);
for (int i = 0; i < 24; ++i) {
sk1.update(i);
@@ -74,7 +74,7 @@
}
TEST_CASE("coupon hash set: check corrupt stream", "[coupon_hash_set]") {
- int lgK = 9;
+ uint8_t lgK = 9;
hll_sketch sk1(lgK);
for (int i = 0; i < 24; ++i) {
sk1.update(i);
@@ -107,13 +107,13 @@
ss.put(HllUtil<>::FAMILY_ID);
ss.seekg(HllUtil<>::MODE_BYTE);
- uint8_t tmp = ss.get();
+ auto tmp = ss.get();
ss.seekp(HllUtil<>::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.put(tmp);
+ ss.put((char)tmp);
ss.seekg(HllUtil<>::LG_ARR_BYTE);
tmp = ss.get();
@@ -123,7 +123,7 @@
hll_sketch::deserialize(ss);
// should work fine despite the corruption
ss.seekp(HllUtil<>::LG_ARR_BYTE);
- ss.put(tmp);
+ ss.put((char)tmp);
}
diff --git a/hll/test/CouponListTest.cpp b/hll/test/CouponListTest.cpp
index 380b60d..86b0dfd 100644
--- a/hll/test/CouponListTest.cpp
+++ b/hll/test/CouponListTest.cpp
@@ -35,9 +35,9 @@
}
TEST_CASE("coupon list: check iterator", "[coupon_list]") {
- int lgConfigK = 8;
+ uint8_t lgConfigK = 8;
CouponList<std::allocator<uint8_t>> cl(lgConfigK, HLL_4, LIST, std::allocator<uint8_t>());
- for (int i = 1; i <= 7; ++i) { cl.couponUpdate(HllUtil<>::pair(i, i)); } // not hashes but distinct values
+ for (uint8_t i = 1; i <= 7; ++i) { cl.couponUpdate(HllUtil<>::pair(i, i)); } // not hashes but distinct values
const int mask = (1 << lgConfigK) - 1;
int idx = 0;
auto itr = cl.begin(false);
@@ -56,7 +56,7 @@
}
TEST_CASE("coupon list: check duplicates and misc", "[coupon_list]") {
- int lgConfigK = 8;
+ uint8_t lgConfigK = 8;
hll_sketch sk(lgConfigK);
for (int i = 1; i <= 7; ++i) {
@@ -79,7 +79,7 @@
REQUIRE(relErr < 0.0);
}
-static void serializeDeserialize(const int lgK) {
+static void serializeDeserialize(uint8_t lgK) {
hll_sketch sk1(lgK);
int u = (lgK < 8) ? 7 : (((1 << (lgK - 3))/ 4) * 3);
@@ -110,7 +110,7 @@
}
TEST_CASE("coupon list: check corrupt bytearray data", "[coupon_list]") {
- int lgK = 6;
+ uint8_t lgK = 6;
hll_sketch sk1(lgK);
sk1.update(1);
sk1.update(2);
@@ -143,7 +143,7 @@
}
TEST_CASE("coupon list: check corrupt stream data", "[coupon_list]") {
- int lgK = 6;
+ uint8_t lgK = 6;
hll_sketch sk1(lgK);
sk1.update(1);
sk1.update(2);
diff --git a/hll/test/CrossCountingTest.cpp b/hll/test/CrossCountingTest.cpp
index 21eb919..aabe741 100644
--- a/hll/test/CrossCountingTest.cpp
+++ b/hll/test/CrossCountingTest.cpp
@@ -26,7 +26,7 @@
namespace datasketches {
-static hll_sketch buildSketch(const int n, const int lgK, const target_hll_type tgtHllType) {
+static hll_sketch buildSketch(const int n, const uint8_t lgK, const target_hll_type tgtHllType) {
hll_sketch sketch(lgK, tgtHllType);
for (int i = 0; i < n; ++i) {
sketch.update(i);
@@ -34,7 +34,7 @@
return sketch;
}
-static void crossCountingCheck(const int lgK, const int n) {
+static void crossCountingCheck(const uint8_t lgK, const int n) {
hll_sketch sk4 = buildSketch(n, lgK, HLL_4);
const double est = sk4.get_estimate();
const double lb = sk4.get_lower_bound(1);
diff --git a/hll/test/HllArrayTest.cpp b/hll/test/HllArrayTest.cpp
index f067dbb..ee001e9 100644
--- a/hll/test/HllArrayTest.cpp
+++ b/hll/test/HllArrayTest.cpp
@@ -25,7 +25,7 @@
namespace datasketches {
-static void testComposite(const int lgK, const target_hll_type tgtHllType, const int n) {
+static void testComposite(uint8_t lgK, const target_hll_type tgtHllType, const int n) {
hll_union u(lgK);
hll_sketch sk(lgK, tgtHllType);
for (int i = 0; i < n; ++i) {
@@ -45,7 +45,7 @@
testComposite(13, target_hll_type::HLL_8, 10000);
}
-static void serializeDeserialize(const int lgK, target_hll_type tgtHllType, const int n) {
+static void serializeDeserialize(uint8_t lgK, target_hll_type tgtHllType, const int n) {
hll_sketch sk1(lgK, tgtHllType);
for (int i = 0; i < n; ++i) {
@@ -72,7 +72,7 @@
}
TEST_CASE("hll array: check serialize deserialize", "[hll_array]") {
- int lgK = 4;
+ uint8_t lgK = 4;
int n = 8;
serializeDeserialize(lgK, HLL_4, n);
serializeDeserialize(lgK, HLL_6, n);
@@ -100,7 +100,7 @@
}
TEST_CASE("hll array: check corrupt bytearray", "[hll_array]") {
- int lgK = 8;
+ uint8_t lgK = 8;
hll_sketch sk1(lgK, HLL_8);
for (int i = 0; i < 50; ++i) {
sk1.update(i);
@@ -138,7 +138,7 @@
}
TEST_CASE("hll array: check corrupt stream", "[hll_array]") {
- int lgK = 6;
+ uint8_t lgK = 6;
hll_sketch sk1(lgK);
for (int i = 0; i < 50; ++i) {
sk1.update(i);
@@ -169,13 +169,13 @@
ss.put(HllUtil<>::FAMILY_ID);
ss.seekg(HllUtil<>::MODE_BYTE);
- uint8_t tmp = ss.get();
+ auto tmp = ss.get();
ss.seekp(HllUtil<>::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.put(tmp);
+ ss.put((char)tmp);
ss.seekg(HllUtil<>::LG_ARR_BYTE);
tmp = ss.get();
@@ -185,7 +185,7 @@
hll_sketch::deserialize(ss);
// should work fine despite the corruption
ss.seekp(HllUtil<>::LG_ARR_BYTE);
- ss.put(tmp);
+ ss.put((char)tmp);
}
} /* namespace datasketches */
diff --git a/hll/test/HllSketchTest.cpp b/hll/test/HllSketchTest.cpp
index 541a70a..c89845f 100644
--- a/hll/test/HllSketchTest.cpp
+++ b/hll/test/HllSketchTest.cpp
@@ -27,7 +27,7 @@
using hll_sketch_test_alloc = hll_sketch_alloc<test_allocator<uint8_t>>;
using alloc = test_allocator<uint8_t>;
-static void runCheckCopy(int lgConfigK, target_hll_type tgtHllType) {
+static void runCheckCopy(uint8_t lgConfigK, target_hll_type tgtHllType) {
hll_sketch_test_alloc sk(lgConfigK, tgtHllType, false, 0);
for (int i = 0; i < 7; ++i) {
@@ -66,7 +66,7 @@
}
static void copyAs(target_hll_type srcType, target_hll_type dstType) {
- int lgK = 8;
+ uint8_t lgK = 8;
int n1 = 7;
int n2 = 24;
int n3 = 1000;
@@ -109,7 +109,7 @@
TEST_CASE("hll sketch: check misc1", "[hll_sketch]") {
test_allocator_total_bytes = 0;
{
- int lgConfigK = 8;
+ uint8_t lgConfigK = 8;
target_hll_type srcType = target_hll_type::HLL_8;
hll_sketch_test_alloc sk(lgConfigK, srcType, false, 0);
@@ -124,7 +124,7 @@
sk.update(24); // HLL
REQUIRE(sk.get_updatable_serialization_bytes() == 40 + 256);
- const int hllBytes = HllUtil<>::HLL_BYTE_ARR_START + (1 << lgConfigK);
+ const auto hllBytes = HllUtil<>::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);
}
@@ -135,13 +135,13 @@
REQUIRE_THROWS_AS(HllUtil<>::checkNumStdDev(0), std::invalid_argument);
}
-void checkSerializationSizes(const int lgConfigK, target_hll_type tgtHllType) {
+void checkSerializationSizes(uint8_t lgConfigK, target_hll_type tgtHllType) {
hll_sketch_test_alloc sk(lgConfigK, tgtHllType, false, 0);
int i;
// LIST
for (i = 0; i < 7; ++i) { sk.update(i); }
- int expected = HllUtil<>::LIST_INT_ARR_START + (i << 2);
+ auto expected = HllUtil<>::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);
REQUIRE(sk.get_updatable_serialization_bytes() == expected);
@@ -178,7 +178,7 @@
// Creates and serializes then deserializes sketch.
// Returns true if deserialized sketch is compact.
-static bool checkCompact(const int lgK, const int n, const target_hll_type type, bool compact) {
+static bool checkCompact(uint8_t lgK, const int n, const target_hll_type type, bool compact) {
hll_sketch_test_alloc sk(lgK, type, false, 0);
for (int i = 0; i < n; ++i) { sk.update(i); }
@@ -201,7 +201,7 @@
TEST_CASE("hll sketch: check compact flag", "[hll_sketch]") {
test_allocator_total_bytes = 0;
{
- int lgK = 8;
+ uint8_t lgK = 8;
// unless/until we create non-updatable "direct" versions,
// deserialized image should never be compact
// LIST: follows serialization request
diff --git a/hll/test/HllUnionTest.cpp b/hll/test/HllUnionTest.cpp
index 3250901..e148e11 100644
--- a/hll/test/HllUnionTest.cpp
+++ b/hll/test/HllUnionTest.cpp
@@ -24,23 +24,19 @@
namespace datasketches {
-static int min(int a, int b) {
- return (a < b) ? a : b;
-}
-
static void println(std::string& str) {
//std::cout << str << "\n";
}
static void basicUnion(uint64_t n1, uint64_t n2,
- uint64_t lgk1, uint64_t lgk2, uint64_t lgMaxK,
+ uint8_t lgk1, uint8_t lgk2, uint8_t lgMaxK,
target_hll_type type1, target_hll_type type2, target_hll_type resultType) {
uint64_t v = 0;
//int tot = n1 + n2;
hll_sketch h1(lgk1, type1);
hll_sketch h2(lgk2, type2);
- int lgControlK = min(min(lgk1, lgk2), lgMaxK);
+ uint8_t lgControlK = std::min(std::min(lgk1, lgk2), lgMaxK);
hll_sketch control(lgControlK, resultType);
for (uint64_t i = 0; i < n1; ++i) {
@@ -89,9 +85,9 @@
target_hll_type type2 = HLL_8;
target_hll_type resultType = HLL_8;
- uint64_t lgK1 = 7;
- uint64_t lgK2 = 7;
- uint64_t lgMaxK = 7;
+ uint8_t lgK1 = 7;
+ uint8_t lgK2 = 7;
+ uint8_t lgMaxK = 7;
uint64_t n1 = 7;
uint64_t n2 = 7;
basicUnion(n1, n2, lgK1, lgK2, lgMaxK, type1, type2, resultType);
@@ -108,7 +104,7 @@
n2 = 14;
basicUnion(n1, n2, lgK1, lgK2, lgMaxK, type1, type2, resultType);
- int i = 0;
+ uint8_t i = 0;
for (i = 7; i <= 13; ++i) {
lgK1 = i;
lgK2 = i;
@@ -195,7 +191,7 @@
}
TEST_CASE("hll union: check ub lb", "[hll_union]") {
- int lgK = 4;
+ uint8_t lgK = 4;
int n = 1 << 20;
bool oooFlag = false;
@@ -223,7 +219,7 @@
}
TEST_CASE("hll union: check conversions", "[hll_union]") {
- int lgK = 4;
+ uint8_t lgK = 4;
hll_sketch sk1(lgK, HLL_8);
hll_sketch sk2(lgK, HLL_8);
int n = 1 << 20;
diff --git a/hll/test/IsomorphicTest.cpp b/hll/test/IsomorphicTest.cpp
index 509469b..df7a9e1 100644
--- a/hll/test/IsomorphicTest.cpp
+++ b/hll/test/IsomorphicTest.cpp
@@ -57,7 +57,7 @@
static long v = 0;
-static hll_sketch build_sketch(int lg_k, target_hll_type hll_type, hll_mode mode) {
+static hll_sketch build_sketch(uint8_t lg_k, target_hll_type hll_type, hll_mode mode) {
hll_sketch sk(lg_k, hll_type);
int n = get_n(lg_k, mode);
for (int i = 0; i < n; i++) sk.update(static_cast<uint64_t>(i + v));
@@ -67,7 +67,7 @@
// merges a sketch to an empty union and gets result of the same type, checks binary equivalence
static void union_one_update(bool compact) {
- for (int lg_k = 4; lg_k <= 21; lg_k++) { // all lg_k
+ for (uint8_t lg_k = 4; lg_k <= 21; lg_k++) { // all lg_k
for (int mode = 0; mode <= 2; mode++) { // List, Set, Hll
if ((lg_k < 8) && (mode == 1)) continue; // lg_k < 8 list transitions directly to HLL
for (int t = 0; t <= 2; t++) { // HLL_4, HLL_6, HLL_8
@@ -102,7 +102,7 @@
// converts a sketch to a different type and converts back to the original type to check binary equivalence
static void convert_back_and_forth(bool compact) {
- for (int lg_k = 4; lg_k <= 21; lg_k++) { // all lg_k
+ for (uint8_t lg_k = 4; lg_k <= 21; lg_k++) { // all lg_k
for (int mode = 0; mode <= 2; mode++) { // List, Set, Hll
if ((lg_k < 8) && (mode == 1)) continue; // lg_k < 8 list transitions directly to HLL
for (int t1 = 0; t1 <= 2; t1++) { // HLL_4, HLL_6, HLL_8
diff --git a/hll/test/ToFromByteArrayTest.cpp b/hll/test/ToFromByteArrayTest.cpp
index 48f49a2..407df0d 100644
--- a/hll/test/ToFromByteArrayTest.cpp
+++ b/hll/test/ToFromByteArrayTest.cpp
@@ -44,11 +44,11 @@
auto ser2 = sk.serialize_updatable();
REQUIRE(ser1.size() == ser2.size());
- int len = ser1.size();
+ auto len = ser1.size();
uint8_t* b1 = ser1.data();
uint8_t* b2 = ser2.data();
- for (int i = 0; i < len; ++i) {
+ for (auto i = 0; i < len; ++i) {
REQUIRE(b2[i] == b1[i]);
}
}
@@ -129,7 +129,7 @@
REQUIRE(sk1.get_target_type() == sk2.get_target_type());
}
-static void toFrom(const int lgConfigK, const target_hll_type tgtHllType, const int n) {
+static void toFrom(const uint8_t lgConfigK, const target_hll_type tgtHllType, const int n) {
hll_sketch src(lgConfigK, tgtHllType);
for (int i = 0; i < n; ++i) {
src.update(i);
@@ -157,7 +157,7 @@
TEST_CASE("hll to/from byte array: to from sketch", "[hll_byte_array]") {
for (int i = 0; i < 10; ++i) {
int n = nArr[i];
- for (int lgK = 4; lgK <= 13; ++lgK) {
+ for (uint8_t lgK = 4; lgK <= 13; ++lgK) {
toFrom(lgK, HLL_4, n);
toFrom(lgK, HLL_6, n);
toFrom(lgK, HLL_8, n);