Skip to content

Commit 10ba66c

Browse files
committed
fix: Add the missing brackets and keep the class member name consistency
1 parent 5a05552 commit 10ba66c

2 files changed

Lines changed: 33 additions & 14 deletions

File tree

count/include/count_min.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ class count_min_sketch{
370370
std::vector<W, Allocator> _sketch_array; // the array stored by the sketch
371371
uint64_t _seed;
372372
W _total_weight;
373-
std::vector<uint64_t> hash_seeds;
373+
std::vector<uint64_t> _hash_seeds;
374374

375375
enum flags {IS_EMPTY};
376376
static const uint8_t PREAMBLE_LONGS_SHORT = 2; // Empty -> need second byte for sketch parameters

count/include/count_min_impl.hpp

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
@@ -50,10 +52,10 @@ _total_weight(0) {
5052

5153
std::default_random_engine rng(_seed);
5254
std::uniform_int_distribution<uint64_t> extra_hash_seeds(0, std::numeric_limits<uint64_t>::max());
53-
hash_seeds.reserve(num_hashes);
55+
_hash_seeds.reserve(num_hashes);
5456

5557
for (uint64_t i=0; i < num_hashes; ++i) {
56-
hash_seeds.push_back(extra_hash_seeds(rng) + _seed); // Adds the global seed to all hash functions.
58+
_hash_seeds.push_back(extra_hash_seeds(rng) + _seed); // Adds the global seed to all hash functions.
5759
}
5860
}
5961

@@ -128,7 +130,7 @@ std::vector<uint64_t> count_min_sketch<W,A>::get_hashes(const void* item, size_t
128130
sketch_update_locations.reserve(_num_hashes);
129131

130132
uint64_t hash_seed_index = 0;
131-
for (const auto &it: hash_seeds) {
133+
for (const auto &it: _hash_seeds) {
132134
HashState hashes;
133135
MurmurHash3_x64_128(item, size, it, hashes); // ? BEWARE OVERFLOW.
134136
uint64_t hash = hashes.h1;
@@ -147,7 +149,9 @@ W count_min_sketch<W,A>::get_estimate(int64_t item) const {return get_estimate(&
147149

148150
template<typename W, typename A>
149151
W 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()) {
153+
return 0; // Empty strings are not inserted into the sketch.
154+
}
151155
return get_estimate(item.c_str(), item.length());
152156
}
153157

@@ -176,7 +180,9 @@ void count_min_sketch<W,A>::update(int64_t item, W weight) {
176180

177181
template<typename W, typename A>
178182
void count_min_sketch<W,A>::update(const std::string& item, W weight) {
179-
if (item.empty()) return;
183+
if (item.empty()) {
184+
return;
185+
}
180186
update(item.c_str(), item.length(), weight);
181187
}
182188

@@ -201,7 +207,9 @@ W count_min_sketch<W,A>::get_upper_bound(int64_t item) const {return get_upper_b
201207

202208
template<typename W, typename A>
203209
W 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.
210+
if (item.empty()) {
211+
return 0; // Empty strings are not inserted into the sketch.
212+
}
205213
return get_upper_bound(item.c_str(), item.length());
206214
}
207215

@@ -218,7 +226,9 @@ W count_min_sketch<W,A>::get_lower_bound(int64_t item) const {return get_lower_b
218226

219227
template<typename W, typename A>
220228
W 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.
229+
if (item.empty()) {
230+
return 0; // Empty strings are not inserted into the sketch.
231+
}
222232
return get_lower_bound(item.c_str(), item.length());
223233
}
224234

@@ -290,7 +300,9 @@ void count_min_sketch<W,A>::serialize(std::ostream& os) const {
290300
write(os, nhashes);
291301
write(os, seed_hash);
292302
write(os, unused8);
293-
if (is_empty()) return; // sketch is empty, no need to write further bytes.
303+
if (is_empty()) {
304+
return; // sketch is empty, no need to write further bytes.
305+
}
294306

295307
// Long 2
296308
write(os, _total_weight);
@@ -327,7 +339,9 @@ auto count_min_sketch<W,A>::deserialize(std::istream& is, uint64_t seed, const A
327339
}
328340
count_min_sketch c(nhashes, nbuckets, seed, allocator);
329341
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.
342+
if (is_empty == 1) {
343+
return c; // sketch is empty, no need to read further.
344+
}
331345

332346
// Set the sketch weight and read in the sketch values
333347
const auto weight = read<W>(is);
@@ -373,7 +387,9 @@ auto count_min_sketch<W,A>::serialize(unsigned header_size_bytes) const -> vecto
373387
ptr += copy_to_mem(nhashes, ptr);
374388
ptr += copy_to_mem(seed_hash, ptr);
375389
ptr += copy_to_mem(null_characters_8, ptr);
376-
if (is_empty()) return bytes; // sketch is empty, no need to write further bytes.
390+
if (is_empty()) {
391+
return bytes; // sketch is empty, no need to write further bytes.
392+
}
377393

378394
// Long 2
379395
const W t_weight = _total_weight;
@@ -423,7 +439,9 @@ auto count_min_sketch<W,A>::deserialize(const void* bytes, size_t size, uint64_t
423439
}
424440
count_min_sketch c(nhashes, nbuckets, seed, allocator);
425441
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.
442+
if (is_empty) {
443+
return c; // sketch is empty, no need to read further.
444+
}
427445

428446
ensure_minimum_memory(size, sizeof(W) * (1 + nbuckets * nhashes));
429447

@@ -449,8 +467,9 @@ string<A> count_min_sketch<W,A>::to_string() const {
449467
// count the number of used entries in the sketch
450468
uint64_t num_nonzero = 0;
451469
for (const auto entry: _sketch_array) {
452-
if (entry != static_cast<W>(0.0))
470+
if (entry != static_cast<W>(0.0)) {
453471
++num_nonzero;
472+
}
454473
}
455474

456475
// Using a temporary stream for implementation here does not comply with AllocatorAwareContainer requirements.

0 commit comments

Comments
 (0)