Skip to content

Commit b8627f4

Browse files
authored
Merge pull request #487 from SYaoJun/223_kll
style(kll): Add braces to single-line if statements for consistency
2 parents eb2ed84 + c764d90 commit b8627f4

2 files changed

Lines changed: 20 additions & 20 deletions

File tree

kll/include/kll_helper_impl.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ bool kll_helper::is_odd(uint32_t value) {
3636
}
3737

3838
uint8_t kll_helper::floor_of_log2_of_fraction(uint64_t numer, uint64_t denom) {
39-
if (denom > numer) return 0;
39+
if (denom > numer) { return 0; }
4040
uint8_t count = 0;
4141
while (true) {
4242
denom <<= 1;
43-
if (denom > numer) return count;
43+
if (denom > numer) { return count; }
4444
count++;
4545
}
4646
}
4747

4848
uint8_t kll_helper::ub_on_num_levels(uint64_t n) {
49-
if (n == 0) return 1;
49+
if (n == 0) { return 1; }
5050
return 1 + floor_of_log2_of_fraction(n, 1);
5151
}
5252

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

6767
uint16_t kll_helper::int_cap_aux(uint16_t k, uint8_t depth) {
68-
if (depth > 60) throw std::invalid_argument("depth > 60");
69-
if (depth <= 30) return int_cap_aux_aux(k, depth);
68+
if (depth > 60) { throw std::invalid_argument("depth > 60"); }
69+
if (depth <= 30) { return int_cap_aux_aux(k, depth); }
7070
const uint8_t half = depth / 2;
7171
const uint8_t rest = depth - half;
7272
const uint16_t tmp = int_cap_aux_aux(k, half);
7373
return int_cap_aux_aux(tmp, rest);
7474
}
7575

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

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

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

111111
template <typename T>
112112
void kll_helper::randomly_halve_up(T* buf, uint32_t start, uint32_t length) {
113-
if (!is_even(length)) throw std::invalid_argument("length must be even");
113+
if (!is_even(length)) { throw std::invalid_argument("length must be even"); }
114114
const uint32_t half_length = length / 2;
115115
#ifdef KLL_VALIDATION
116116
const uint32_t offset = deterministic_offset();
@@ -206,7 +206,7 @@ template <typename T, typename C>
206206
kll_helper::compress_result kll_helper::general_compress(uint16_t k, uint8_t m, uint8_t num_levels_in, T* items,
207207
uint32_t* in_levels, uint32_t* out_levels, bool is_level_zero_sorted)
208208
{
209-
if (num_levels_in == 0) throw std::invalid_argument("num_levels_in == 0"); // things are too weird if zero levels are allowed
209+
if (num_levels_in == 0) { throw std::invalid_argument("num_levels_in == 0"); } // things are too weird if zero levels are allowed
210210
const uint32_t starting_item_count = in_levels[num_levels_in] - in_levels[0];
211211
uint8_t current_num_levels = num_levels_in;
212212
uint32_t current_item_count = starting_item_count; // decreases with each compaction

kll/include/kll_sketch_impl.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ void kll_sketch<T, C, A>::update_min_max(const T& item) {
199199

200200
template<typename T, typename C, typename A>
201201
uint32_t kll_sketch<T, C, A>::internal_update() {
202-
if (levels_[0] == 0) compress_while_updating();
202+
if (levels_[0] == 0) { compress_while_updating(); }
203203
n_++;
204204
is_level_zero_sorted_ = false;
205205
return --levels_[0];
@@ -208,7 +208,7 @@ uint32_t kll_sketch<T, C, A>::internal_update() {
208208
template<typename T, typename C, typename A>
209209
template<typename FwdSk>
210210
void kll_sketch<T, C, A>::merge(FwdSk&& other) {
211-
if (other.is_empty()) return;
211+
if (other.is_empty()) { return; }
212212
if (m_ != other.m_) {
213213
throw std::invalid_argument("incompatible M: " + std::to_string(m_) + " and " + std::to_string(other.m_));
214214
}
@@ -224,9 +224,9 @@ void kll_sketch<T, C, A>::merge(FwdSk&& other) {
224224
const uint32_t index = internal_update();
225225
new (&items_[index]) T(conditional_forward<FwdSk>(other.items_[i]));
226226
}
227-
if (other.num_levels_ >= 2) merge_higher_levels(other, final_n);
227+
if (other.num_levels_ >= 2) { merge_higher_levels(other, final_n); }
228228
n_ = final_n;
229-
if (other.is_estimation_mode()) min_k_ = std::min(min_k_, other.min_k_);
229+
if (other.is_estimation_mode()) { min_k_ = std::min(min_k_, other.min_k_); }
230230
assert_correct_total_weight();
231231
reset_sorted_view();
232232
}
@@ -258,13 +258,13 @@ bool kll_sketch<T, C, A>::is_estimation_mode() const {
258258

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)