@@ -39,7 +39,9 @@ _num_buckets(num_buckets),
3939_sketch_array((num_hashes*num_buckets < 1 <<30 ) ? num_hashes*num_buckets : 0, 0, _allocator),
4040_seed(seed),
4141_total_weight(0 ) {
42- if (num_buckets < 3 ) throw std::invalid_argument (" Using fewer than 3 buckets incurs relative error greater than 1." );
42+ if (num_buckets < 3 ) {
43+ throw std::invalid_argument (" Using fewer than 3 buckets incurs relative error greater than 1." );
44+ }
4345
4446 // This check is to ensure later compatibility with a Java implementation whose maximum size can only
4547 // be 2^31-1. We check only against 2^30 for simplicity.
@@ -147,7 +149,7 @@ W count_min_sketch<W,A>::get_estimate(int64_t item) const {return get_estimate(&
147149
148150template <typename W, typename A>
149151W count_min_sketch<W,A>::get_estimate(const std::string& item) const {
150- if (item.empty ()) return 0 ; // Empty strings are not inserted into the sketch.
152+ if (item.empty ()) { return 0 ; } // Empty strings are not inserted into the sketch.
151153 return get_estimate (item.c_str (), item.length ());
152154}
153155
@@ -176,7 +178,7 @@ void count_min_sketch<W,A>::update(int64_t item, W weight) {
176178
177179template <typename W, typename A>
178180void count_min_sketch<W,A>::update(const std::string& item, W weight) {
179- if (item.empty ()) return ;
181+ if (item.empty ()) { return ; }
180182 update (item.c_str (), item.length (), weight);
181183}
182184
@@ -201,7 +203,7 @@ W count_min_sketch<W,A>::get_upper_bound(int64_t item) const {return get_upper_b
201203
202204template <typename W, typename A>
203205W count_min_sketch<W,A>::get_upper_bound(const std::string& item) const {
204- if (item.empty ()) return 0 ; // Empty strings are not inserted into the sketch.
206+ if (item.empty ()) { return 0 ; } // Empty strings are not inserted into the sketch.
205207 return get_upper_bound (item.c_str (), item.length ());
206208}
207209
@@ -218,7 +220,7 @@ W count_min_sketch<W,A>::get_lower_bound(int64_t item) const {return get_lower_b
218220
219221template <typename W, typename A>
220222W count_min_sketch<W,A>::get_lower_bound(const std::string& item) const {
221- if (item.empty ()) return 0 ; // Empty strings are not inserted into the sketch.
223+ if (item.empty ()) { return 0 ; } // Empty strings are not inserted into the sketch.
222224 return get_lower_bound (item.c_str (), item.length ());
223225}
224226
@@ -232,17 +234,13 @@ void count_min_sketch<W,A>::merge(const count_min_sketch &other_sketch) {
232234 /*
233235 * Merges this sketch into other_sketch sketch by elementwise summing of buckets
234236 */
235- if (this == &other_sketch) {
236- throw std::invalid_argument ( " Cannot merge a sketch with itself." );
237- }
237+ if (this == &other_sketch) { throw std::invalid_argument ( " Cannot merge a sketch with itself." ); }
238238
239239 bool acceptable_config =
240240 (get_num_hashes () == other_sketch.get_num_hashes ()) &&
241241 (get_num_buckets () == other_sketch.get_num_buckets ()) &&
242242 (get_seed () == other_sketch.get_seed ());
243- if (!acceptable_config) {
244- throw std::invalid_argument ( " Incompatible sketch configuration." );
245- }
243+ if (!acceptable_config) { throw std::invalid_argument ( " Incompatible sketch configuration." ); }
246244
247245 // Merge step - iterate over the other vector and add the weights to this sketch
248246 auto it = _sketch_array.begin (); // This is a std::vector iterator.
@@ -290,7 +288,7 @@ void count_min_sketch<W,A>::serialize(std::ostream& os) const {
290288 write (os, nhashes);
291289 write (os, seed_hash);
292290 write (os, unused8);
293- if (is_empty ()) return ; // sketch is empty, no need to write further bytes.
291+ if (is_empty ()) { return ; } // sketch is empty, no need to write further bytes.
294292
295293 // Long 2
296294 write (os, _total_weight);
@@ -327,7 +325,7 @@ auto count_min_sketch<W,A>::deserialize(std::istream& is, uint64_t seed, const A
327325 }
328326 count_min_sketch c (nhashes, nbuckets, seed, allocator);
329327 const bool is_empty = (flags_byte & (1 << flags::IS_EMPTY)) > 0 ;
330- if (is_empty == 1 ) return c; // sketch is empty, no need to read further.
328+ if (is_empty == 1 ) { return c; } // sketch is empty, no need to read further.
331329
332330 // Set the sketch weight and read in the sketch values
333331 const auto weight = read<W>(is);
@@ -373,7 +371,7 @@ auto count_min_sketch<W,A>::serialize(unsigned header_size_bytes) const -> vecto
373371 ptr += copy_to_mem (nhashes, ptr);
374372 ptr += copy_to_mem (seed_hash, ptr);
375373 ptr += copy_to_mem (null_characters_8, ptr);
376- if (is_empty ()) return bytes; // sketch is empty, no need to write further bytes.
374+ if (is_empty ()) { return bytes; } // sketch is empty, no need to write further bytes.
377375
378376 // Long 2
379377 const W t_weight = _total_weight;
@@ -423,7 +421,7 @@ auto count_min_sketch<W,A>::deserialize(const void* bytes, size_t size, uint64_t
423421 }
424422 count_min_sketch c (nhashes, nbuckets, seed, allocator);
425423 const bool is_empty = (flags_byte & (1 << flags::IS_EMPTY)) > 0 ;
426- if (is_empty) return c; // sketch is empty, no need to read further.
424+ if (is_empty) { return c; } // sketch is empty, no need to read further.
427425
428426 ensure_minimum_memory (size, sizeof (W) * (1 + nbuckets * nhashes));
429427
@@ -449,9 +447,7 @@ string<A> count_min_sketch<W,A>::to_string() const {
449447 // count the number of used entries in the sketch
450448 uint64_t num_nonzero = 0 ;
451449 for (const auto entry: _sketch_array) {
452- if (entry != static_cast <W>(0.0 )){
453- ++num_nonzero;
454- }
450+ if (entry != static_cast <W>(0.0 )) { ++num_nonzero; }
455451 }
456452
457453 // Using a temporary stream for implementation here does not comply with AllocatorAwareContainer requirements.
0 commit comments