Skip to content

Commit 69c3773

Browse files
authored
Merge pull request #491 from SYaoJun/223_cpc
style(cpc): Fix missing braces in if statements in cpc/include
2 parents 143bf17 + 4e92e0b commit 69c3773

File tree

5 files changed

+90
-89
lines changed

5 files changed

+90
-89
lines changed

cpc/include/cpc_sketch_impl.hpp

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ bool cpc_sketch_alloc<A>::is_empty() const {
7373

7474
template<typename A>
7575
double cpc_sketch_alloc<A>::get_estimate() const {
76-
if (!was_merged) return get_hip_estimate();
76+
if (!was_merged) { return get_hip_estimate(); }
7777
return get_icon_estimate();
7878
}
7979

@@ -92,7 +92,7 @@ double cpc_sketch_alloc<A>::get_lower_bound(unsigned kappa) const {
9292
if (kappa < 1 || kappa > 3) {
9393
throw std::invalid_argument("kappa must be 1, 2 or 3");
9494
}
95-
if (!was_merged) return get_hip_confidence_lb<A>(*this, kappa);
95+
if (!was_merged) { return get_hip_confidence_lb<A>(*this, kappa); }
9696
return get_icon_confidence_lb<A>(*this, kappa);
9797
}
9898

@@ -101,13 +101,13 @@ double cpc_sketch_alloc<A>::get_upper_bound(unsigned kappa) const {
101101
if (kappa < 1 || kappa > 3) {
102102
throw std::invalid_argument("kappa must be 1, 2 or 3");
103103
}
104-
if (!was_merged) return get_hip_confidence_ub<A>(*this, kappa);
104+
if (!was_merged) { return get_hip_confidence_ub<A>(*this, kappa); }
105105
return get_icon_confidence_ub<A>(*this, kappa);
106106
}
107107

108108
template<typename A>
109109
void cpc_sketch_alloc<A>::update(const std::string& value) {
110-
if (value.empty()) return;
110+
if (value.empty()) { return; }
111111
update(value.c_str(), value.length());
112112
}
113113

@@ -173,15 +173,15 @@ void cpc_sketch_alloc<A>::update(float value) {
173173
}
174174

175175
static inline uint32_t row_col_from_two_hashes(uint64_t hash0, uint64_t hash1, uint8_t lg_k) {
176-
if (lg_k > 26) throw std::logic_error("lg_k > 26");
176+
if (lg_k > 26) { throw std::logic_error("lg_k > 26"); }
177177
const uint32_t k = 1 << lg_k;
178178
uint8_t col = count_leading_zeros_in_u64(hash1); // 0 <= col <= 64
179-
if (col > 63) col = 63; // clip so that 0 <= col <= 63
179+
if (col > 63) { col = 63; } // clip so that 0 <= col <= 63
180180
const uint32_t row = hash0 & (k - 1);
181181
uint32_t row_col = (row << 6) | col;
182182
// To avoid the hash table's "empty" value, we change the row of the following pair.
183183
// This case is extremely unlikely, but we might as well handle it.
184-
if (row_col == UINT32_MAX) row_col ^= 1 << 6;
184+
if (row_col == UINT32_MAX) { row_col ^= 1 << 6; }
185185
return row_col;
186186
}
187187

@@ -195,7 +195,7 @@ void cpc_sketch_alloc<A>::update(const void* value, size_t size) {
195195
template<typename A>
196196
void cpc_sketch_alloc<A>::row_col_update(uint32_t row_col) {
197197
const uint8_t col = row_col & 63;
198-
if (col < first_interesting_column) return; // important speed optimization
198+
if (col < first_interesting_column) { return; } // important speed optimization
199199
// window size is 0 until sketch is promoted from sparse to windowed
200200
if (sliding_window.size() == 0) {
201201
update_sparse(row_col);
@@ -208,34 +208,34 @@ template<typename A>
208208
void cpc_sketch_alloc<A>::update_sparse(uint32_t row_col) {
209209
const uint32_t k = 1 << lg_k;
210210
const uint64_t c32pre = static_cast<uint64_t>(num_coupons) << 5;
211-
if (c32pre >= 3 * k) throw std::logic_error("c32pre >= 3 * k"); // C < 3K/32, in other words flavor == SPARSE
211+
if (c32pre >= 3 * k) { throw std::logic_error("c32pre >= 3 * k"); } // C < 3K/32, in other words flavor == SPARSE
212212
bool is_novel = surprising_value_table.maybe_insert(row_col);
213213
if (is_novel) {
214214
num_coupons++;
215215
update_hip(row_col);
216216
const uint64_t c32post = static_cast<uint64_t>(num_coupons) << 5;
217-
if (c32post >= 3 * k) promote_sparse_to_windowed(); // C >= 3K/32
217+
if (c32post >= 3 * k) { promote_sparse_to_windowed(); } // C >= 3K/32
218218
}
219219
}
220220

221221
// the flavor is HYBRID, PINNED, or SLIDING
222222
template<typename A>
223223
void cpc_sketch_alloc<A>::update_windowed(uint32_t row_col) {
224-
if (window_offset > 56) throw std::logic_error("wrong window offset");
224+
if (window_offset > 56) { throw std::logic_error("wrong window offset"); }
225225
const uint32_t k = 1 << lg_k;
226226
const uint64_t c32pre = static_cast<uint64_t>(num_coupons) << 5;
227-
if (c32pre < 3 * k) throw std::logic_error("c32pre < 3 * k"); // C < 3K/32, in other words flavor >= HYBRID
227+
if (c32pre < 3 * k) { throw std::logic_error("c32pre < 3 * k"); } // C < 3K/32, in other words flavor >= HYBRID
228228
const uint64_t c8pre = static_cast<uint64_t>(num_coupons) << 3;
229229
const uint64_t w8pre = static_cast<uint64_t>(window_offset) << 3;
230-
if (c8pre >= (27 + w8pre) * k) throw std::logic_error("c8pre is wrong"); // C < (K * 27/8) + (K * window_offset)
230+
if (c8pre >= (27 + w8pre) * k) { throw std::logic_error("c8pre is wrong"); } // C < (K * 27/8) + (K * window_offset)
231231

232232
bool is_novel = false;
233233
const uint8_t col = row_col & 63;
234234

235235
if (col < window_offset) { // track the surprising 0's "before" the window
236236
is_novel = surprising_value_table.maybe_delete(row_col); // inverted logic
237237
} else if (col < window_offset + 8) { // track the 8 bits inside the window
238-
if (col < window_offset) throw std::logic_error("col < window_offset");
238+
if (col < window_offset) { throw std::logic_error("col < window_offset"); }
239239
const uint32_t row = row_col >> 6;
240240
const uint8_t old_bits = sliding_window[row];
241241
const uint8_t new_bits = old_bits | (1 << (col - window_offset));
@@ -244,7 +244,7 @@ void cpc_sketch_alloc<A>::update_windowed(uint32_t row_col) {
244244
is_novel = true;
245245
}
246246
} else { // track the surprising 1's "after" the window
247-
if (col < window_offset + 8) throw std::logic_error("col < window_offset + 8");
247+
if (col < window_offset + 8) { throw std::logic_error("col < window_offset + 8"); }
248248
is_novel = surprising_value_table.maybe_insert(row_col); // normal logic
249249
}
250250

@@ -254,9 +254,9 @@ void cpc_sketch_alloc<A>::update_windowed(uint32_t row_col) {
254254
const uint64_t c8post = static_cast<uint64_t>(num_coupons) << 3;
255255
if (c8post >= (27 + w8pre) * k) {
256256
move_window();
257-
if (window_offset < 1 || window_offset > 56) throw std::logic_error("wrong window offset");
257+
if (window_offset < 1 || window_offset > 56) { throw std::logic_error("wrong window offset"); }
258258
const uint64_t w8post = static_cast<uint64_t>(window_offset) << 3;
259-
if (c8post >= (27 + w8post) * k) throw std::logic_error("c8pre is wrong"); // C < (K * 27/8) + (K * window_offset)
259+
if (c8post >= (27 + w8post) * k) { throw std::logic_error("c8pre is wrong"); } // C < (K * 27/8) + (K * window_offset)
260260
}
261261
}
262262
}
@@ -276,7 +276,7 @@ template<typename A>
276276
void cpc_sketch_alloc<A>::promote_sparse_to_windowed() {
277277
const uint32_t k = 1 << lg_k;
278278
const uint64_t c32 = static_cast<uint64_t>(num_coupons) << 5;
279-
if (!(c32 == 3 * k || (lg_k == 4 && c32 > 3 * k))) throw std::logic_error("wrong c32");
279+
if (!(c32 == 3 * k || (lg_k == 4 && c32 > 3 * k))) { throw std::logic_error("wrong c32"); }
280280

281281
sliding_window.resize(k, 0); // zero the memory (because we will be OR'ing into it)
282282

@@ -285,7 +285,7 @@ void cpc_sketch_alloc<A>::promote_sparse_to_windowed() {
285285
const uint32_t* old_slots = surprising_value_table.get_slots();
286286
const uint32_t old_num_slots = 1 << surprising_value_table.get_lg_size();
287287

288-
if (window_offset != 0) throw std::logic_error("window_offset != 0");
288+
if (window_offset != 0) { throw std::logic_error("window_offset != 0"); }
289289

290290
for (uint32_t i = 0; i < old_num_slots; i++) {
291291
const uint32_t row_col = old_slots[i];
@@ -297,7 +297,7 @@ void cpc_sketch_alloc<A>::promote_sparse_to_windowed() {
297297
} else {
298298
// cannot use u32_table::must_insert(), because it doesn't provide for growth
299299
const bool is_novel = new_table.maybe_insert(row_col);
300-
if (!is_novel) throw std::logic_error("is_novel != true");
300+
if (!is_novel) { throw std::logic_error("is_novel != true"); }
301301
}
302302
}
303303
}
@@ -308,17 +308,17 @@ void cpc_sketch_alloc<A>::promote_sparse_to_windowed() {
308308
template<typename A>
309309
void cpc_sketch_alloc<A>::move_window() {
310310
const uint8_t new_offset = window_offset + 1;
311-
if (new_offset > 56) throw std::logic_error("new_offset > 56");
312-
if (new_offset != determine_correct_offset(lg_k, num_coupons)) throw std::logic_error("new_offset is wrong");
311+
if (new_offset > 56) { throw std::logic_error("new_offset > 56"); }
312+
if (new_offset != determine_correct_offset(lg_k, num_coupons)) { throw std::logic_error("new_offset is wrong"); }
313313

314-
if (sliding_window.size() == 0) throw std::logic_error("no sliding window");
314+
if (sliding_window.size() == 0) { throw std::logic_error("no sliding window"); }
315315
const uint32_t k = 1 << lg_k;
316316

317317
// Construct the full-sized bit matrix that corresponds to the sketch
318318
vector_u64 bit_matrix = build_bit_matrix();
319319

320320
// refresh the KXP register on every 8th window shift.
321-
if ((new_offset & 0x7) == 0) refresh_kxp(bit_matrix.data());
321+
if ((new_offset & 0x7) == 0) { refresh_kxp(bit_matrix.data()); }
322322

323323
surprising_value_table.clear(); // the new number of surprises will be about the same
324324

@@ -339,14 +339,14 @@ void cpc_sketch_alloc<A>::move_window() {
339339
pattern = pattern ^ (static_cast<uint64_t>(1) << col); // erase the 1
340340
const uint32_t row_col = (i << 6) | col;
341341
const bool is_novel = surprising_value_table.maybe_insert(row_col);
342-
if (!is_novel) throw std::logic_error("is_novel != true");
342+
if (!is_novel) { throw std::logic_error("is_novel != true"); }
343343
}
344344
}
345345

346346
window_offset = new_offset;
347347

348348
first_interesting_column = count_trailing_zeros_in_u64(all_surprises_ored);
349-
if (first_interesting_column > new_offset) first_interesting_column = new_offset; // corner case
349+
if (first_interesting_column > new_offset) { first_interesting_column = new_offset; } // corner case
350350
}
351351

352352
// The KXP register is a double with roughly 50 bits of precision, but
@@ -438,7 +438,7 @@ void cpc_sketch_alloc<A>::serialize(std::ostream& os) const {
438438
write(os, compressed.table_num_entries);
439439
// HIP values can be in two different places in the sequence of fields
440440
// this is the first HIP decision point
441-
if (has_hip) write_hip(os);
441+
if (has_hip) { write_hip(os); }
442442
}
443443
if (has_table) {
444444
write(os, compressed.table_data_words);
@@ -447,7 +447,7 @@ void cpc_sketch_alloc<A>::serialize(std::ostream& os) const {
447447
write(os, compressed.window_data_words);
448448
}
449449
// this is the second HIP decision point
450-
if (has_hip && !(has_table && has_window)) write_hip(os);
450+
if (has_hip && !(has_table && has_window)) { write_hip(os); }
451451
if (has_window) {
452452
write(os, compressed.window_data.data(), compressed.window_data_words * sizeof(uint32_t));
453453
}
@@ -494,7 +494,7 @@ auto cpc_sketch_alloc<A>::serialize(unsigned header_size_bytes) const -> vector_
494494
ptr += copy_to_mem(compressed.table_num_entries, ptr);
495495
// HIP values can be in two different places in the sequence of fields
496496
// this is the first HIP decision point
497-
if (has_hip) ptr += copy_hip_to_mem(ptr);
497+
if (has_hip) { ptr += copy_hip_to_mem(ptr); }
498498
}
499499
if (has_table) {
500500
ptr += copy_to_mem(compressed.table_data_words, ptr);
@@ -503,15 +503,15 @@ auto cpc_sketch_alloc<A>::serialize(unsigned header_size_bytes) const -> vector_
503503
ptr += copy_to_mem(compressed.window_data_words, ptr);
504504
}
505505
// this is the second HIP decision point
506-
if (has_hip && !(has_table && has_window)) ptr += copy_hip_to_mem(ptr);
506+
if (has_hip && !(has_table && has_window)) { ptr += copy_hip_to_mem(ptr); }
507507
if (has_window) {
508508
ptr += copy_to_mem(compressed.window_data.data(), ptr, compressed.window_data_words * sizeof(uint32_t));
509509
}
510510
if (has_table) {
511511
ptr += copy_to_mem(compressed.table_data.data(), ptr, compressed.table_data_words * sizeof(uint32_t));
512512
}
513513
}
514-
if (ptr != bytes.data() + size) throw std::logic_error("serialized size mismatch");
514+
if (ptr != bytes.data() + size) { throw std::logic_error("serialized size mismatch"); }
515515
return bytes;
516516
}
517517

@@ -561,7 +561,7 @@ cpc_sketch_alloc<A> cpc_sketch_alloc<A>::deserialize(std::istream& is, uint64_t
561561
compressed.table_data.resize(compressed.table_data_words);
562562
read(is, compressed.table_data.data(), compressed.table_data_words * sizeof(uint32_t));
563563
}
564-
if (!has_window) compressed.table_num_entries = num_coupons;
564+
if (!has_window) { compressed.table_num_entries = num_coupons; }
565565
}
566566

567567
uint8_t expected_preamble_ints = get_preamble_ints(num_coupons, has_hip, has_table, has_window);
@@ -583,8 +583,9 @@ cpc_sketch_alloc<A> cpc_sketch_alloc<A>::deserialize(std::istream& is, uint64_t
583583
}
584584
uncompressed_state<A> uncompressed(allocator);
585585
get_compressor<A>().uncompress(compressed, uncompressed, lg_k, num_coupons);
586-
if (!is.good())
587-
throw std::runtime_error("error reading from std::istream");
586+
if (!is.good()) {
587+
throw std::runtime_error("error reading from std::istream");
588+
}
588589
return cpc_sketch_alloc(lg_k, num_coupons, first_interesting_column, std::move(uncompressed.table),
589590
std::move(uncompressed.window), has_hip, kxp, hip_est_accum, seed);
590591
}

0 commit comments

Comments
 (0)