diff --git a/kll/include/kll_helper_impl.hpp b/kll/include/kll_helper_impl.hpp index bb92bdc7..31534d9a 100644 --- a/kll/include/kll_helper_impl.hpp +++ b/kll/include/kll_helper_impl.hpp @@ -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); } @@ -65,8 +65,8 @@ 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); @@ -74,11 +74,11 @@ uint16_t kll_helper::int_cap_aux(uint16_t k, uint8_t depth) { } 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(result); } @@ -94,7 +94,7 @@ uint64_t kll_helper::sum_the_sample_weights(uint8_t num_levels, const uint32_t* template 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(); @@ -110,7 +110,7 @@ void kll_helper::randomly_halve_down(T* buf, uint32_t start, uint32_t length) { template 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(); @@ -206,7 +206,7 @@ template 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 diff --git a/kll/include/kll_sketch_impl.hpp b/kll/include/kll_sketch_impl.hpp index 44fe6a15..b12a39c8 100644 --- a/kll/include/kll_sketch_impl.hpp +++ b/kll/include/kll_sketch_impl.hpp @@ -199,7 +199,7 @@ void kll_sketch::update_min_max(const T& item) { template uint32_t kll_sketch::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]; @@ -208,7 +208,7 @@ uint32_t kll_sketch::internal_update() { template template void kll_sketch::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_)); } @@ -224,9 +224,9 @@ void kll_sketch::merge(FwdSk&& other) { const uint32_t index = internal_update(); new (&items_[index]) T(conditional_forward(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(); } @@ -258,13 +258,13 @@ bool kll_sketch::is_estimation_mode() const { template T kll_sketch::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 T kll_sketch::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_; } @@ -280,28 +280,28 @@ A kll_sketch::get_allocator() const { template double kll_sketch::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 auto kll_sketch::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 auto kll_sketch::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 auto kll_sketch::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"); }