From 4e92e0bd71db0d00af93e3be6fc8a3f9152173e1 Mon Sep 17 00:00:00 2001 From: syaojun Date: Mon, 23 Feb 2026 15:13:51 +0800 Subject: [PATCH] style(cpc): Fix missing braces in if statements in cpc/include --- cpc/include/cpc_sketch_impl.hpp | 69 +++++++++++++++++---------------- cpc/include/cpc_union_impl.hpp | 54 +++++++++++++------------- cpc/include/cpc_util.hpp | 14 +++---- cpc/include/icon_estimator.hpp | 10 ++--- cpc/include/u32_table_impl.hpp | 32 +++++++-------- 5 files changed, 90 insertions(+), 89 deletions(-) diff --git a/cpc/include/cpc_sketch_impl.hpp b/cpc/include/cpc_sketch_impl.hpp index 84709cdc..80f111f1 100644 --- a/cpc/include/cpc_sketch_impl.hpp +++ b/cpc/include/cpc_sketch_impl.hpp @@ -73,7 +73,7 @@ bool cpc_sketch_alloc::is_empty() const { template double cpc_sketch_alloc::get_estimate() const { - if (!was_merged) return get_hip_estimate(); + if (!was_merged) { return get_hip_estimate(); } return get_icon_estimate(); } @@ -92,7 +92,7 @@ double cpc_sketch_alloc::get_lower_bound(unsigned kappa) const { if (kappa < 1 || kappa > 3) { throw std::invalid_argument("kappa must be 1, 2 or 3"); } - if (!was_merged) return get_hip_confidence_lb(*this, kappa); + if (!was_merged) { return get_hip_confidence_lb(*this, kappa); } return get_icon_confidence_lb(*this, kappa); } @@ -101,13 +101,13 @@ double cpc_sketch_alloc::get_upper_bound(unsigned kappa) const { if (kappa < 1 || kappa > 3) { throw std::invalid_argument("kappa must be 1, 2 or 3"); } - if (!was_merged) return get_hip_confidence_ub(*this, kappa); + if (!was_merged) { return get_hip_confidence_ub(*this, kappa); } return get_icon_confidence_ub(*this, kappa); } template void cpc_sketch_alloc::update(const std::string& value) { - if (value.empty()) return; + if (value.empty()) { return; } update(value.c_str(), value.length()); } @@ -173,15 +173,15 @@ void cpc_sketch_alloc::update(float value) { } static inline uint32_t row_col_from_two_hashes(uint64_t hash0, uint64_t hash1, uint8_t lg_k) { - if (lg_k > 26) throw std::logic_error("lg_k > 26"); + if (lg_k > 26) { throw std::logic_error("lg_k > 26"); } const uint32_t k = 1 << lg_k; uint8_t col = count_leading_zeros_in_u64(hash1); // 0 <= col <= 64 - if (col > 63) col = 63; // clip so that 0 <= col <= 63 + if (col > 63) { col = 63; } // clip so that 0 <= col <= 63 const uint32_t row = hash0 & (k - 1); uint32_t row_col = (row << 6) | col; // To avoid the hash table's "empty" value, we change the row of the following pair. // This case is extremely unlikely, but we might as well handle it. - if (row_col == UINT32_MAX) row_col ^= 1 << 6; + if (row_col == UINT32_MAX) { row_col ^= 1 << 6; } return row_col; } @@ -195,7 +195,7 @@ void cpc_sketch_alloc::update(const void* value, size_t size) { template void cpc_sketch_alloc::row_col_update(uint32_t row_col) { const uint8_t col = row_col & 63; - if (col < first_interesting_column) return; // important speed optimization + if (col < first_interesting_column) { return; } // important speed optimization // window size is 0 until sketch is promoted from sparse to windowed if (sliding_window.size() == 0) { update_sparse(row_col); @@ -208,26 +208,26 @@ template void cpc_sketch_alloc::update_sparse(uint32_t row_col) { const uint32_t k = 1 << lg_k; const uint64_t c32pre = static_cast(num_coupons) << 5; - if (c32pre >= 3 * k) throw std::logic_error("c32pre >= 3 * k"); // C < 3K/32, in other words flavor == SPARSE + if (c32pre >= 3 * k) { throw std::logic_error("c32pre >= 3 * k"); } // C < 3K/32, in other words flavor == SPARSE bool is_novel = surprising_value_table.maybe_insert(row_col); if (is_novel) { num_coupons++; update_hip(row_col); const uint64_t c32post = static_cast(num_coupons) << 5; - if (c32post >= 3 * k) promote_sparse_to_windowed(); // C >= 3K/32 + if (c32post >= 3 * k) { promote_sparse_to_windowed(); } // C >= 3K/32 } } // the flavor is HYBRID, PINNED, or SLIDING template void cpc_sketch_alloc::update_windowed(uint32_t row_col) { - if (window_offset > 56) throw std::logic_error("wrong window offset"); + if (window_offset > 56) { throw std::logic_error("wrong window offset"); } const uint32_t k = 1 << lg_k; const uint64_t c32pre = static_cast(num_coupons) << 5; - if (c32pre < 3 * k) throw std::logic_error("c32pre < 3 * k"); // C < 3K/32, in other words flavor >= HYBRID + if (c32pre < 3 * k) { throw std::logic_error("c32pre < 3 * k"); } // C < 3K/32, in other words flavor >= HYBRID const uint64_t c8pre = static_cast(num_coupons) << 3; const uint64_t w8pre = static_cast(window_offset) << 3; - if (c8pre >= (27 + w8pre) * k) throw std::logic_error("c8pre is wrong"); // C < (K * 27/8) + (K * window_offset) + if (c8pre >= (27 + w8pre) * k) { throw std::logic_error("c8pre is wrong"); } // C < (K * 27/8) + (K * window_offset) bool is_novel = false; const uint8_t col = row_col & 63; @@ -235,7 +235,7 @@ void cpc_sketch_alloc::update_windowed(uint32_t row_col) { if (col < window_offset) { // track the surprising 0's "before" the window is_novel = surprising_value_table.maybe_delete(row_col); // inverted logic } else if (col < window_offset + 8) { // track the 8 bits inside the window - if (col < window_offset) throw std::logic_error("col < window_offset"); + if (col < window_offset) { throw std::logic_error("col < window_offset"); } const uint32_t row = row_col >> 6; const uint8_t old_bits = sliding_window[row]; const uint8_t new_bits = old_bits | (1 << (col - window_offset)); @@ -244,7 +244,7 @@ void cpc_sketch_alloc::update_windowed(uint32_t row_col) { is_novel = true; } } else { // track the surprising 1's "after" the window - if (col < window_offset + 8) throw std::logic_error("col < window_offset + 8"); + if (col < window_offset + 8) { throw std::logic_error("col < window_offset + 8"); } is_novel = surprising_value_table.maybe_insert(row_col); // normal logic } @@ -254,9 +254,9 @@ void cpc_sketch_alloc::update_windowed(uint32_t row_col) { const uint64_t c8post = static_cast(num_coupons) << 3; if (c8post >= (27 + w8pre) * k) { move_window(); - if (window_offset < 1 || window_offset > 56) throw std::logic_error("wrong window offset"); + if (window_offset < 1 || window_offset > 56) { throw std::logic_error("wrong window offset"); } const uint64_t w8post = static_cast(window_offset) << 3; - if (c8post >= (27 + w8post) * k) throw std::logic_error("c8pre is wrong"); // C < (K * 27/8) + (K * window_offset) + if (c8post >= (27 + w8post) * k) { throw std::logic_error("c8pre is wrong"); } // C < (K * 27/8) + (K * window_offset) } } } @@ -276,7 +276,7 @@ template void cpc_sketch_alloc::promote_sparse_to_windowed() { const uint32_t k = 1 << lg_k; const uint64_t c32 = static_cast(num_coupons) << 5; - if (!(c32 == 3 * k || (lg_k == 4 && c32 > 3 * k))) throw std::logic_error("wrong c32"); + if (!(c32 == 3 * k || (lg_k == 4 && c32 > 3 * k))) { throw std::logic_error("wrong c32"); } sliding_window.resize(k, 0); // zero the memory (because we will be OR'ing into it) @@ -285,7 +285,7 @@ void cpc_sketch_alloc::promote_sparse_to_windowed() { const uint32_t* old_slots = surprising_value_table.get_slots(); const uint32_t old_num_slots = 1 << surprising_value_table.get_lg_size(); - if (window_offset != 0) throw std::logic_error("window_offset != 0"); + if (window_offset != 0) { throw std::logic_error("window_offset != 0"); } for (uint32_t i = 0; i < old_num_slots; i++) { const uint32_t row_col = old_slots[i]; @@ -297,7 +297,7 @@ void cpc_sketch_alloc::promote_sparse_to_windowed() { } else { // cannot use u32_table::must_insert(), because it doesn't provide for growth const bool is_novel = new_table.maybe_insert(row_col); - if (!is_novel) throw std::logic_error("is_novel != true"); + if (!is_novel) { throw std::logic_error("is_novel != true"); } } } } @@ -308,17 +308,17 @@ void cpc_sketch_alloc::promote_sparse_to_windowed() { template void cpc_sketch_alloc::move_window() { const uint8_t new_offset = window_offset + 1; - if (new_offset > 56) throw std::logic_error("new_offset > 56"); - if (new_offset != determine_correct_offset(lg_k, num_coupons)) throw std::logic_error("new_offset is wrong"); + if (new_offset > 56) { throw std::logic_error("new_offset > 56"); } + if (new_offset != determine_correct_offset(lg_k, num_coupons)) { throw std::logic_error("new_offset is wrong"); } - if (sliding_window.size() == 0) throw std::logic_error("no sliding window"); + if (sliding_window.size() == 0) { throw std::logic_error("no sliding window"); } const uint32_t k = 1 << lg_k; // Construct the full-sized bit matrix that corresponds to the sketch vector_u64 bit_matrix = build_bit_matrix(); // refresh the KXP register on every 8th window shift. - if ((new_offset & 0x7) == 0) refresh_kxp(bit_matrix.data()); + if ((new_offset & 0x7) == 0) { refresh_kxp(bit_matrix.data()); } surprising_value_table.clear(); // the new number of surprises will be about the same @@ -339,14 +339,14 @@ void cpc_sketch_alloc::move_window() { pattern = pattern ^ (static_cast(1) << col); // erase the 1 const uint32_t row_col = (i << 6) | col; const bool is_novel = surprising_value_table.maybe_insert(row_col); - if (!is_novel) throw std::logic_error("is_novel != true"); + if (!is_novel) { throw std::logic_error("is_novel != true"); } } } window_offset = new_offset; first_interesting_column = count_trailing_zeros_in_u64(all_surprises_ored); - if (first_interesting_column > new_offset) first_interesting_column = new_offset; // corner case + if (first_interesting_column > new_offset) { first_interesting_column = new_offset; } // corner case } // The KXP register is a double with roughly 50 bits of precision, but @@ -438,7 +438,7 @@ void cpc_sketch_alloc::serialize(std::ostream& os) const { write(os, compressed.table_num_entries); // HIP values can be in two different places in the sequence of fields // this is the first HIP decision point - if (has_hip) write_hip(os); + if (has_hip) { write_hip(os); } } if (has_table) { write(os, compressed.table_data_words); @@ -447,7 +447,7 @@ void cpc_sketch_alloc::serialize(std::ostream& os) const { write(os, compressed.window_data_words); } // this is the second HIP decision point - if (has_hip && !(has_table && has_window)) write_hip(os); + if (has_hip && !(has_table && has_window)) { write_hip(os); } if (has_window) { write(os, compressed.window_data.data(), compressed.window_data_words * sizeof(uint32_t)); } @@ -494,7 +494,7 @@ auto cpc_sketch_alloc::serialize(unsigned header_size_bytes) const -> vector_ ptr += copy_to_mem(compressed.table_num_entries, ptr); // HIP values can be in two different places in the sequence of fields // this is the first HIP decision point - if (has_hip) ptr += copy_hip_to_mem(ptr); + if (has_hip) { ptr += copy_hip_to_mem(ptr); } } if (has_table) { ptr += copy_to_mem(compressed.table_data_words, ptr); @@ -503,7 +503,7 @@ auto cpc_sketch_alloc::serialize(unsigned header_size_bytes) const -> vector_ ptr += copy_to_mem(compressed.window_data_words, ptr); } // this is the second HIP decision point - if (has_hip && !(has_table && has_window)) ptr += copy_hip_to_mem(ptr); + if (has_hip && !(has_table && has_window)) { ptr += copy_hip_to_mem(ptr); } if (has_window) { ptr += copy_to_mem(compressed.window_data.data(), ptr, compressed.window_data_words * sizeof(uint32_t)); } @@ -511,7 +511,7 @@ auto cpc_sketch_alloc::serialize(unsigned header_size_bytes) const -> vector_ ptr += copy_to_mem(compressed.table_data.data(), ptr, compressed.table_data_words * sizeof(uint32_t)); } } - if (ptr != bytes.data() + size) throw std::logic_error("serialized size mismatch"); + if (ptr != bytes.data() + size) { throw std::logic_error("serialized size mismatch"); } return bytes; } @@ -561,7 +561,7 @@ cpc_sketch_alloc cpc_sketch_alloc::deserialize(std::istream& is, uint64_t compressed.table_data.resize(compressed.table_data_words); read(is, compressed.table_data.data(), compressed.table_data_words * sizeof(uint32_t)); } - if (!has_window) compressed.table_num_entries = num_coupons; + if (!has_window) { compressed.table_num_entries = num_coupons; } } uint8_t expected_preamble_ints = get_preamble_ints(num_coupons, has_hip, has_table, has_window); @@ -583,8 +583,9 @@ cpc_sketch_alloc cpc_sketch_alloc::deserialize(std::istream& is, uint64_t } uncompressed_state uncompressed(allocator); get_compressor().uncompress(compressed, uncompressed, lg_k, num_coupons); - if (!is.good()) - throw std::runtime_error("error reading from std::istream"); + if (!is.good()) { + throw std::runtime_error("error reading from std::istream"); + } return cpc_sketch_alloc(lg_k, num_coupons, first_interesting_column, std::move(uncompressed.table), std::move(uncompressed.window), has_hip, kxp, hip_est_accum, seed); } diff --git a/cpc/include/cpc_union_impl.hpp b/cpc/include/cpc_union_impl.hpp index f277107f..673aa7a4 100644 --- a/cpc/include/cpc_union_impl.hpp +++ b/cpc/include/cpc_union_impl.hpp @@ -109,15 +109,15 @@ void cpc_union_alloc::internal_update(S&& sketch) { + std::to_string(seed_hash_sketch)); } const auto src_flavor = sketch.determine_flavor(); - if (cpc_sketch_alloc::flavor::EMPTY == src_flavor) return; + if (cpc_sketch_alloc::flavor::EMPTY == src_flavor) { return; } - if (sketch.get_lg_k() < lg_k) reduce_k(sketch.get_lg_k()); - if (sketch.get_lg_k() < lg_k) throw std::logic_error("sketch lg_k < union lg_k"); + if (sketch.get_lg_k() < lg_k) { reduce_k(sketch.get_lg_k()); } + if (sketch.get_lg_k() < lg_k) { throw std::logic_error("sketch lg_k < union lg_k"); } - if (accumulator == nullptr && bit_matrix.size() == 0) throw std::logic_error("both accumulator and bit matrix are absent"); + if (accumulator == nullptr && bit_matrix.size() == 0) { throw std::logic_error("both accumulator and bit matrix are absent"); } if (cpc_sketch_alloc::flavor::SPARSE == src_flavor && accumulator != nullptr) { // Case A - if (bit_matrix.size() > 0) throw std::logic_error("union bit_matrix is not expected"); + if (bit_matrix.size() > 0) { throw std::logic_error("union bit_matrix is not expected"); } const auto initial_dest_flavor = accumulator->determine_flavor(); if (cpc_sketch_alloc::flavor::EMPTY != initial_dest_flavor && cpc_sketch_alloc::flavor::SPARSE != initial_dest_flavor) throw std::logic_error("wrong flavor"); @@ -138,24 +138,24 @@ void cpc_union_alloc::internal_update(S&& sketch) { } if (cpc_sketch_alloc::flavor::SPARSE == src_flavor && bit_matrix.size() > 0) { // Case B - if (accumulator != nullptr) throw std::logic_error("union accumulator != null"); + if (accumulator != nullptr) { throw std::logic_error("union accumulator != null"); } or_table_into_matrix(sketch.surprising_value_table); return; } if (cpc_sketch_alloc::flavor::HYBRID != src_flavor && cpc_sketch_alloc::flavor::PINNED != src_flavor - && cpc_sketch_alloc::flavor::SLIDING != src_flavor) throw std::logic_error("wrong flavor"); + && cpc_sketch_alloc::flavor::SLIDING != src_flavor) { throw std::logic_error("wrong flavor"); } // source is past SPARSE mode, so make sure that dest is a bit matrix if (accumulator != nullptr) { - if (bit_matrix.size() > 0) throw std::logic_error("union bit matrix is not expected"); + if (bit_matrix.size() > 0) { throw std::logic_error("union bit matrix is not expected"); } const auto dst_flavor = accumulator->determine_flavor(); if (cpc_sketch_alloc::flavor::EMPTY != dst_flavor && cpc_sketch_alloc::flavor::SPARSE != dst_flavor) { throw std::logic_error("wrong flavor"); } switch_to_bit_matrix(); } - if (bit_matrix.size() == 0) throw std::logic_error("union bit_matrix is expected"); + if (bit_matrix.size() == 0) { throw std::logic_error("union bit_matrix is expected"); } if (cpc_sketch_alloc::flavor::HYBRID == src_flavor || cpc_sketch_alloc::flavor::PINNED == src_flavor) { // Case C or_window_into_matrix(sketch.sliding_window, sketch.window_offset, sketch.get_lg_k()); @@ -165,7 +165,7 @@ void cpc_union_alloc::internal_update(S&& sketch) { // SLIDING mode involves inverted logic, so we can't just walk the source sketch. // Instead, we convert it to a bitMatrix that can be OR'ed into the destination. - if (cpc_sketch_alloc::flavor::SLIDING != src_flavor) throw std::logic_error("wrong flavor"); // Case D + if (cpc_sketch_alloc::flavor::SLIDING != src_flavor) { throw std::logic_error("wrong flavor"); } // Case D vector_u64 src_matrix = sketch.build_bit_matrix(); or_matrix_into_matrix(src_matrix, sketch.get_lg_k()); } @@ -173,20 +173,20 @@ void cpc_union_alloc::internal_update(S&& sketch) { template cpc_sketch_alloc cpc_union_alloc::get_result() const { if (accumulator != nullptr) { - if (bit_matrix.size() > 0) throw std::logic_error("bit_matrix is not expected"); + if (bit_matrix.size() > 0) { throw std::logic_error("bit_matrix is not expected"); } return get_result_from_accumulator(); } - if (bit_matrix.size() == 0) throw std::logic_error("bit_matrix is expected"); + if (bit_matrix.size() == 0) { throw std::logic_error("bit_matrix is expected"); } return get_result_from_bit_matrix(); } template cpc_sketch_alloc cpc_union_alloc::get_result_from_accumulator() const { - if (lg_k != accumulator->get_lg_k()) throw std::logic_error("lg_k != accumulator->lg_k"); + if (lg_k != accumulator->get_lg_k()) { throw std::logic_error("lg_k != accumulator->lg_k"); } if (accumulator->get_num_coupons() == 0) { return cpc_sketch_alloc(lg_k, seed, accumulator->get_allocator()); } - if (accumulator->determine_flavor() != cpc_sketch_alloc::flavor::SPARSE) throw std::logic_error("wrong flavor"); + if (accumulator->determine_flavor() != cpc_sketch_alloc::flavor::SPARSE) { throw std::logic_error("wrong flavor"); } cpc_sketch_alloc copy(*accumulator); copy.was_merged = true; return copy; @@ -199,7 +199,7 @@ cpc_sketch_alloc cpc_union_alloc::get_result_from_bit_matrix() const { const auto flavor = cpc_sketch_alloc::determine_flavor(lg_k, num_coupons); if (flavor != cpc_sketch_alloc::flavor::HYBRID && flavor != cpc_sketch_alloc::flavor::PINNED - && flavor != cpc_sketch_alloc::flavor::SLIDING) throw std::logic_error("wrong flavor"); + && flavor != cpc_sketch_alloc::flavor::SLIDING) { throw std::logic_error("wrong flavor"); } const uint8_t offset = cpc_sketch_alloc::determine_correct_offset(lg_k, num_coupons); @@ -208,7 +208,7 @@ cpc_sketch_alloc cpc_union_alloc::get_result_from_bit_matrix() const { // dynamically growing caused snowplow effect uint8_t table_lg_size = lg_k - 4; // K/16; in some cases this will end up being oversized - if (table_lg_size < 2) table_lg_size = 2; + if (table_lg_size < 2) { table_lg_size = 2; } u32_table table(table_lg_size, 6 + lg_k, bit_matrix.get_allocator()); // the following should work even when the offset is zero @@ -229,14 +229,14 @@ cpc_sketch_alloc cpc_union_alloc::get_result_from_bit_matrix() const { pattern = pattern ^ (static_cast(1) << col); // erase the 1 const uint32_t row_col = (i << 6) | col; bool is_novel = table.maybe_insert(row_col); - if (!is_novel) throw std::logic_error("is_novel != true"); + if (!is_novel) { throw std::logic_error("is_novel != true"); } } } // at this point we could shrink an oversized hash table, but the relative waste isn't very big uint8_t first_interesting_column = count_trailing_zeros_in_u64(all_surprises_ored); - if (first_interesting_column > offset) first_interesting_column = offset; // corner case + if (first_interesting_column > offset) { first_interesting_column = offset; } // corner case // HIP-related fields will contain zeros, and that is okay return cpc_sketch_alloc(lg_k, num_coupons, first_interesting_column, std::move(table), std::move(sliding_window), false, 0, 0, seed); @@ -260,9 +260,9 @@ void cpc_union_alloc::walk_table_updating_sketch(const u32_table& table) { // Using a golden ratio stride fixes the snowplow effect. const double golden = 0.6180339887498949025; uint32_t stride = static_cast(golden * static_cast(num_slots)); - if (stride < 2) throw std::logic_error("stride < 2"); - if (stride == ((stride >> 1) << 1)) stride += 1; // force the stride to be odd - if (stride < 3 || stride >= num_slots) throw std::out_of_range("stride out of range"); + if (stride < 2) { throw std::logic_error("stride < 2"); } + if (stride == ((stride >> 1) << 1)) { stride += 1; } // force the stride to be odd + if (stride < 3 || stride >= num_slots) { throw std::out_of_range("stride out of range"); } for (uint32_t i = 0, j = 0; i < num_slots; i++, j += stride) { j &= num_slots - 1; @@ -290,7 +290,7 @@ void cpc_union_alloc::or_table_into_matrix(const u32_table& table) { template void cpc_union_alloc::or_window_into_matrix(const vector_bytes& sliding_window, uint8_t offset, uint8_t src_lg_k) { - if (lg_k > src_lg_k) throw std::logic_error("dst LgK > src LgK"); + if (lg_k > src_lg_k) { throw std::logic_error("dst LgK > src LgK"); } const uint64_t dst_mask = (1 << lg_k) - 1; // downsamples when dst lgK < src LgK const uint32_t src_k = 1 << src_lg_k; for (uint32_t src_row = 0; src_row < src_k; src_row++) { @@ -300,7 +300,7 @@ void cpc_union_alloc::or_window_into_matrix(const vector_bytes& sliding_windo template void cpc_union_alloc::or_matrix_into_matrix(const vector_u64& src_matrix, uint8_t src_lg_k) { - if (lg_k > src_lg_k) throw std::logic_error("dst LgK > src LgK"); + if (lg_k > src_lg_k) { throw std::logic_error("dst LgK > src LgK"); } const uint64_t dst_mask = (1 << lg_k) - 1; // downsamples when dst lgK < src LgK const uint32_t src_k = 1 << src_lg_k; for (uint32_t src_row = 0; src_row < src_k; src_row++) { @@ -310,11 +310,11 @@ void cpc_union_alloc::or_matrix_into_matrix(const vector_u64& src_matrix, uin template void cpc_union_alloc::reduce_k(uint8_t new_lg_k) { - if (new_lg_k >= lg_k) throw std::logic_error("new LgK >= union lgK"); - if (accumulator == nullptr && bit_matrix.size() == 0) throw std::logic_error("both accumulator and bit_matrix are absent"); + if (new_lg_k >= lg_k) { throw std::logic_error("new LgK >= union lgK"); } + if (accumulator == nullptr && bit_matrix.size() == 0) { throw std::logic_error("both accumulator and bit_matrix are absent"); } if (bit_matrix.size() > 0) { // downsample the unioner's bit matrix - if (accumulator != nullptr) throw std::logic_error("accumulator is not null"); + if (accumulator != nullptr) { throw std::logic_error("accumulator is not null"); } vector_u64 old_matrix = std::move(bit_matrix); const uint8_t old_lg_k = lg_k; const uint32_t new_k = 1 << new_lg_k; @@ -325,7 +325,7 @@ void cpc_union_alloc::reduce_k(uint8_t new_lg_k) { } if (accumulator != nullptr) { // downsample the unioner's sketch - if (bit_matrix.size() > 0) throw std::logic_error("bit_matrix is not expected"); + if (bit_matrix.size() > 0) { throw std::logic_error("bit_matrix is not expected"); } if (!accumulator->is_empty()) { cpc_sketch_alloc old_accumulator(*accumulator); *accumulator = cpc_sketch_alloc(new_lg_k, seed, old_accumulator.get_allocator()); diff --git a/cpc/include/cpc_util.hpp b/cpc/include/cpc_util.hpp index e5664951..c9da8ab7 100644 --- a/cpc/include/cpc_util.hpp +++ b/cpc/include/cpc_util.hpp @@ -25,19 +25,19 @@ namespace datasketches { static inline uint64_t divide_longs_rounding_up(uint64_t x, uint64_t y) { - if (y == 0) throw std::invalid_argument("divide_longs_rounding_up: bad argument"); + if (y == 0) { throw std::invalid_argument("divide_longs_rounding_up: bad argument"); } const uint64_t quotient = x / y; - if (quotient * y == x) return (quotient); - else return quotient + 1; + if (quotient * y == x) { return (quotient); } + else { return quotient + 1; } } static inline uint8_t floor_log2_of_long(uint64_t x) { - if (x < 1) throw std::invalid_argument("floor_log2_of_long: bad argument"); + if (x < 1) { throw std::invalid_argument("floor_log2_of_long: bad argument"); } uint8_t p = 0; uint64_t y = 1; while (true) { - if (y == x) return p; - if (y > x) return p - 1; + if (y == x) { return p; } + if (y > x) { return p - 1; } p += 1; y <<= 1; } @@ -98,7 +98,7 @@ static inline uint32_t warren_count_bits_set_in_matrix(const uint64_t* array, ui } static inline uint32_t count_bits_set_in_matrix(const uint64_t* a, uint32_t length) { - if ((length & 0x7) != 0) throw std::invalid_argument("the length of the array must be a multiple of 8"); + if ((length & 0x7) != 0) { throw std::invalid_argument("the length of the array must be a multiple of 8"); } uint32_t total = 0; uint64_t ones, twos, twos_a, twos_b, fours, fours_a, fours_b, eights; fours = twos = ones = 0; diff --git a/cpc/include/icon_estimator.hpp b/cpc/include/icon_estimator.hpp index fb3c0c60..ade787e5 100644 --- a/cpc/include/icon_estimator.hpp +++ b/cpc/include/icon_estimator.hpp @@ -246,14 +246,14 @@ static inline double icon_exponential_approximation(double k, double c) { } static inline double compute_icon_estimate(uint8_t lg_k, uint32_t c) { - if (lg_k < ICON_MIN_LOG_K || lg_k > ICON_MAX_LOG_K) throw std::out_of_range("lg_k out of range"); - if (c < 2) return ((c == 0) ? 0.0 : 1.0); + if (lg_k < ICON_MIN_LOG_K || lg_k > ICON_MAX_LOG_K) { throw std::out_of_range("lg_k out of range"); } + if (c < 2) { return ((c == 0) ? 0.0 : 1.0); } const uint32_t k = 1 << lg_k; const double double_k = static_cast(k); const double double_c = static_cast(c); // Differing thresholds ensure that the approximated estimator is monotonically increasing. const double threshold_factor = ((lg_k < 14) ? 5.7 : 5.6); - if (double_c > (threshold_factor * double_k)) return icon_exponential_approximation(double_k, double_c); + if (double_c > (threshold_factor * double_k)) { return icon_exponential_approximation(double_k, double_c); } const double factor = evaluate_polynomial( ICON_POLYNOMIAL_COEFFICIENTS, ICON_POLYNOMIAL_NUM_COEFFICIENTS * (lg_k - ICON_MIN_LOG_K), @@ -265,8 +265,8 @@ static inline double compute_icon_estimate(uint8_t lg_k, uint32_t c) { // The somewhat arbitrary constant 66.774757 is baked into the table ICON_POLYNOMIAL_COEFFICIENTS const double term = 1.0 + (ratio * ratio * ratio / 66.774757); const double result = double_c * factor * term; - if (result >= double_c) return result; - else return double_c; + if (result >= double_c) { return result; } + else { return double_c; } } } /* namespace datasketches */ diff --git a/cpc/include/u32_table_impl.hpp b/cpc/include/u32_table_impl.hpp index 62cd7dac..85797bcf 100644 --- a/cpc/include/u32_table_impl.hpp +++ b/cpc/include/u32_table_impl.hpp @@ -43,8 +43,8 @@ num_valid_bits(num_valid_bits), num_items(0), slots(1ULL << lg_size, UINT32_MAX, allocator) { - if (lg_size < 2) throw std::invalid_argument("lg_size must be >= 2"); - if (num_valid_bits < 1 || num_valid_bits > 32) throw std::invalid_argument("num_valid_bits must be between 1 and 32"); + if (lg_size < 2) { throw std::invalid_argument("lg_size must be >= 2"); } + if (num_valid_bits < 1 || num_valid_bits > 32) { throw std::invalid_argument("num_valid_bits must be between 1 and 32"); } } template @@ -71,8 +71,8 @@ void u32_table::clear() { template bool u32_table::maybe_insert(uint32_t item) { const uint32_t index = lookup(item); - if (slots[index] == item) return false; - if (slots[index] != UINT32_MAX) throw std::logic_error("could not insert"); + if (slots[index] == item) { return false; } + if (slots[index] != UINT32_MAX) { throw std::logic_error("could not insert"); } slots[index] = item; num_items++; if (U32_TABLE_UPSIZE_DENOM * num_items > U32_TABLE_UPSIZE_NUMER * (1 << lg_size)) { @@ -84,9 +84,9 @@ bool u32_table::maybe_insert(uint32_t item) { template bool u32_table::maybe_delete(uint32_t item) { const uint32_t index = lookup(item); - if (slots[index] == UINT32_MAX) return false; - if (slots[index] != item) throw std::logic_error("item does not exist"); - if (num_items == 0) throw std::logic_error("delete error"); + if (slots[index] == UINT32_MAX) { return false; } + if (slots[index] != item) { throw std::logic_error("item does not exist"); } + if (num_items == 0) { throw std::logic_error("delete error"); } // delete the item slots[index] = UINT32_MAX; num_items--; @@ -129,7 +129,7 @@ uint32_t u32_table::lookup(uint32_t item) const { const uint32_t mask = size - 1; const uint8_t shift = num_valid_bits - lg_size; uint32_t probe = item >> shift; - if (probe > mask) throw std::logic_error("probe out of range"); + if (probe > mask) { throw std::logic_error("probe out of range"); } while (slots[probe] != item && slots[probe] != UINT32_MAX) { probe = (probe + 1) & mask; } @@ -140,17 +140,17 @@ uint32_t u32_table::lookup(uint32_t item) const { template void u32_table::must_insert(uint32_t item) { const uint32_t index = lookup(item); - if (slots[index] == item) throw std::logic_error("item exists"); - if (slots[index] != UINT32_MAX) throw std::logic_error("could not insert"); + if (slots[index] == item) { throw std::logic_error("item exists"); } + if (slots[index] != UINT32_MAX) { throw std::logic_error("could not insert"); } slots[index] = item; } template void u32_table::rebuild(uint8_t new_lg_size) { - if (new_lg_size < 2) throw std::logic_error("lg_size must be >= 2"); + if (new_lg_size < 2) { throw std::logic_error("lg_size must be >= 2"); } const uint32_t old_size = 1 << lg_size; const uint32_t new_size = 1 << new_lg_size; - if (new_size <= num_items) throw std::logic_error("new_size <= num_items"); + if (new_size <= num_items) { throw std::logic_error("new_size <= num_items"); } vector_u32 old_slots = std::move(slots); slots = vector_u32(new_size, UINT32_MAX, old_slots.get_allocator()); lg_size = new_lg_size; @@ -169,7 +169,7 @@ void u32_table::rebuild(uint8_t new_lg_size) { // The result is nearly sorted, so make sure to use an efficient sort for that case template auto u32_table::unwrapping_get_items() const -> vector_u32 { - if (num_items == 0) return vector_u32(slots.get_allocator()); + if (num_items == 0) { return vector_u32(slots.get_allocator()); } const uint32_t table_size = 1 << lg_size; vector_u32 result(num_items, 0, slots.get_allocator()); size_t i = 0; @@ -187,9 +187,9 @@ auto u32_table::unwrapping_get_items() const -> vector_u32 { // the rest of the table is processed normally while (i < table_size) { const uint32_t item = slots[i++]; - if (item != UINT32_MAX) result[l++] = item; + if (item != UINT32_MAX) { result[l++] = item; } } - if (l != r + 1) throw std::logic_error("unwrapping error"); + if (l != r + 1) { throw std::logic_error("unwrapping error"); } return result; } @@ -213,7 +213,7 @@ void u32_table::merge( else if (arr_a[a] < arr_b[b]) { arr_c[c] = arr_a[a++]; } else { arr_c[c] = arr_b[b++]; } } - if (a != lim_a || b != lim_b) throw std::logic_error("merging error"); + if (a != lim_a || b != lim_b) { throw std::logic_error("merging error"); } } // In applications where the input array is already nearly sorted,