Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions kll/include/kll_helper_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ bool kll_helper::is_odd(uint32_t value) {
}

uint8_t kll_helper::floor_of_log2_of_fraction(uint64_t numer, uint64_t denom) {
if (denom > numer) return 0;
if (denom > numer) { return 0; }
uint8_t count = 0;
while (true) {
denom <<= 1;
if (denom > numer) return count;
if (denom > numer) { return count; }
count++;
}
}

uint8_t kll_helper::ub_on_num_levels(uint64_t n) {
if (n == 0) return 1;
if (n == 0) { return 1; }
return 1 + floor_of_log2_of_fraction(n, 1);
}

Expand All @@ -65,20 +65,20 @@ uint16_t kll_helper::level_capacity(uint16_t k, uint8_t numLevels, uint8_t heigh
}

uint16_t kll_helper::int_cap_aux(uint16_t k, uint8_t depth) {
if (depth > 60) throw std::invalid_argument("depth > 60");
if (depth <= 30) return int_cap_aux_aux(k, depth);
if (depth > 60) { throw std::invalid_argument("depth > 60"); }
if (depth <= 30) { return int_cap_aux_aux(k, depth); }
const uint8_t half = depth / 2;
const uint8_t rest = depth - half;
const uint16_t tmp = int_cap_aux_aux(k, half);
return int_cap_aux_aux(tmp, rest);
}

uint16_t kll_helper::int_cap_aux_aux(uint16_t k, uint8_t depth) {
if (depth > 30) throw std::invalid_argument("depth > 30");
if (depth > 30) { throw std::invalid_argument("depth > 30"); }
const uint64_t twok = k << 1; // for rounding, we pre-multiply by 2
const uint64_t tmp = (uint64_t) (((uint64_t) twok << depth) / powers_of_three[depth]);
const uint64_t result = (tmp + 1) >> 1; // then here we add 1 and divide by 2
if (result > k) throw std::logic_error("result > k");
if (result > k) { throw std::logic_error("result > k"); }
return static_cast<uint16_t>(result);
}

Expand All @@ -94,7 +94,7 @@ uint64_t kll_helper::sum_the_sample_weights(uint8_t num_levels, const uint32_t*

template <typename T>
void kll_helper::randomly_halve_down(T* buf, uint32_t start, uint32_t length) {
if (!is_even(length)) throw std::invalid_argument("length must be even");
if (!is_even(length)) { throw std::invalid_argument("length must be even"); }
const uint32_t half_length = length / 2;
#ifdef KLL_VALIDATION
const uint32_t offset = deterministic_offset();
Expand All @@ -110,7 +110,7 @@ void kll_helper::randomly_halve_down(T* buf, uint32_t start, uint32_t length) {

template <typename T>
void kll_helper::randomly_halve_up(T* buf, uint32_t start, uint32_t length) {
if (!is_even(length)) throw std::invalid_argument("length must be even");
if (!is_even(length)) { throw std::invalid_argument("length must be even"); }
const uint32_t half_length = length / 2;
#ifdef KLL_VALIDATION
const uint32_t offset = deterministic_offset();
Expand Down Expand Up @@ -206,7 +206,7 @@ template <typename T, typename C>
kll_helper::compress_result kll_helper::general_compress(uint16_t k, uint8_t m, uint8_t num_levels_in, T* items,
uint32_t* in_levels, uint32_t* out_levels, bool is_level_zero_sorted)
{
if (num_levels_in == 0) throw std::invalid_argument("num_levels_in == 0"); // things are too weird if zero levels are allowed
if (num_levels_in == 0) { throw std::invalid_argument("num_levels_in == 0"); } // things are too weird if zero levels are allowed
const uint32_t starting_item_count = in_levels[num_levels_in] - in_levels[0];
uint8_t current_num_levels = num_levels_in;
uint32_t current_item_count = starting_item_count; // decreases with each compaction
Expand Down
20 changes: 10 additions & 10 deletions kll/include/kll_sketch_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void kll_sketch<T, C, A>::update_min_max(const T& item) {

template<typename T, typename C, typename A>
uint32_t kll_sketch<T, C, A>::internal_update() {
if (levels_[0] == 0) compress_while_updating();
if (levels_[0] == 0) { compress_while_updating(); }
n_++;
is_level_zero_sorted_ = false;
return --levels_[0];
Expand All @@ -208,7 +208,7 @@ uint32_t kll_sketch<T, C, A>::internal_update() {
template<typename T, typename C, typename A>
template<typename FwdSk>
void kll_sketch<T, C, A>::merge(FwdSk&& other) {
if (other.is_empty()) return;
if (other.is_empty()) { return; }
if (m_ != other.m_) {
throw std::invalid_argument("incompatible M: " + std::to_string(m_) + " and " + std::to_string(other.m_));
}
Expand All @@ -224,9 +224,9 @@ void kll_sketch<T, C, A>::merge(FwdSk&& other) {
const uint32_t index = internal_update();
new (&items_[index]) T(conditional_forward<FwdSk>(other.items_[i]));
}
if (other.num_levels_ >= 2) merge_higher_levels(other, final_n);
if (other.num_levels_ >= 2) { merge_higher_levels(other, final_n); }
n_ = final_n;
if (other.is_estimation_mode()) min_k_ = std::min(min_k_, other.min_k_);
if (other.is_estimation_mode()) { min_k_ = std::min(min_k_, other.min_k_); }
assert_correct_total_weight();
reset_sorted_view();
}
Expand Down Expand Up @@ -258,13 +258,13 @@ bool kll_sketch<T, C, A>::is_estimation_mode() const {

template<typename T, typename C, typename A>
T kll_sketch<T, C, A>::get_min_item() const {
if (is_empty()) throw std::runtime_error("operation is undefined for an empty sketch");
if (is_empty()) { throw std::runtime_error("operation is undefined for an empty sketch"); }
return *min_item_;
}

template<typename T, typename C, typename A>
T kll_sketch<T, C, A>::get_max_item() const {
if (is_empty()) throw std::runtime_error("operation is undefined for an empty sketch");
if (is_empty()) { throw std::runtime_error("operation is undefined for an empty sketch"); }
return *max_item_;
}

Expand All @@ -280,28 +280,28 @@ A kll_sketch<T, C, A>::get_allocator() const {

template<typename T, typename C, typename A>
double kll_sketch<T, C, A>::get_rank(const T& item, bool inclusive) const {
if (is_empty()) throw std::runtime_error("operation is undefined for an empty sketch");
if (is_empty()) { throw std::runtime_error("operation is undefined for an empty sketch"); }
setup_sorted_view();
return sorted_view_->get_rank(item, inclusive);
}

template<typename T, typename C, typename A>
auto kll_sketch<T, C, A>::get_PMF(const T* split_points, uint32_t size, bool inclusive) const -> vector_double {
if (is_empty()) throw std::runtime_error("operation is undefined for an empty sketch");
if (is_empty()) { throw std::runtime_error("operation is undefined for an empty sketch"); }
setup_sorted_view();
return sorted_view_->get_PMF(split_points, size, inclusive);
}

template<typename T, typename C, typename A>
auto kll_sketch<T, C, A>::get_CDF(const T* split_points, uint32_t size, bool inclusive) const -> vector_double {
if (is_empty()) throw std::runtime_error("operation is undefined for an empty sketch");
if (is_empty()) { throw std::runtime_error("operation is undefined for an empty sketch"); }
setup_sorted_view();
return sorted_view_->get_CDF(split_points, size, inclusive);
}

template<typename T, typename C, typename A>
auto kll_sketch<T, C, A>::get_quantile(double rank, bool inclusive) const -> quantile_return_type {
if (is_empty()) throw std::runtime_error("operation is undefined for an empty sketch");
if (is_empty()) { throw std::runtime_error("operation is undefined for an empty sketch"); }
if ((rank < 0.0) || (rank > 1.0)) {
throw std::invalid_argument("normalized rank cannot be less than zero or greater than 1.0");
}
Expand Down