From 10ba66cc8920341e3b5214a82bc66f69698eeed7 Mon Sep 17 00:00:00 2001 From: yaojun <940334249@qq.com> Date: Sat, 31 Jan 2026 13:48:52 +0800 Subject: [PATCH] fix: Add the missing brackets and keep the class member name consistency --- count/include/count_min.hpp | 2 +- count/include/count_min_impl.hpp | 45 +++++++++++++++++++++++--------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/count/include/count_min.hpp b/count/include/count_min.hpp index 1fbba0e6..3122a6c2 100644 --- a/count/include/count_min.hpp +++ b/count/include/count_min.hpp @@ -370,7 +370,7 @@ class count_min_sketch{ std::vector _sketch_array; // the array stored by the sketch uint64_t _seed; W _total_weight; - std::vector hash_seeds; + std::vector _hash_seeds; enum flags {IS_EMPTY}; static const uint8_t PREAMBLE_LONGS_SHORT = 2; // Empty -> need second byte for sketch parameters diff --git a/count/include/count_min_impl.hpp b/count/include/count_min_impl.hpp index 45376e7b..14a93461 100644 --- a/count/include/count_min_impl.hpp +++ b/count/include/count_min_impl.hpp @@ -39,7 +39,9 @@ _num_buckets(num_buckets), _sketch_array((num_hashes*num_buckets < 1<<30) ? num_hashes*num_buckets : 0, 0, _allocator), _seed(seed), _total_weight(0) { - if (num_buckets < 3) throw std::invalid_argument("Using fewer than 3 buckets incurs relative error greater than 1."); + if (num_buckets < 3) { + throw std::invalid_argument("Using fewer than 3 buckets incurs relative error greater than 1."); + } // This check is to ensure later compatibility with a Java implementation whose maximum size can only // be 2^31-1. We check only against 2^30 for simplicity. @@ -50,10 +52,10 @@ _total_weight(0) { std::default_random_engine rng(_seed); std::uniform_int_distribution extra_hash_seeds(0, std::numeric_limits::max()); - hash_seeds.reserve(num_hashes); + _hash_seeds.reserve(num_hashes); for (uint64_t i=0; i < num_hashes; ++i) { - hash_seeds.push_back(extra_hash_seeds(rng) + _seed); // Adds the global seed to all hash functions. + _hash_seeds.push_back(extra_hash_seeds(rng) + _seed); // Adds the global seed to all hash functions. } } @@ -128,7 +130,7 @@ std::vector count_min_sketch::get_hashes(const void* item, size_t sketch_update_locations.reserve(_num_hashes); uint64_t hash_seed_index = 0; - for (const auto &it: hash_seeds) { + for (const auto &it: _hash_seeds) { HashState hashes; MurmurHash3_x64_128(item, size, it, hashes); // ? BEWARE OVERFLOW. uint64_t hash = hashes.h1; @@ -147,7 +149,9 @@ W count_min_sketch::get_estimate(int64_t item) const {return get_estimate(& template W count_min_sketch::get_estimate(const std::string& item) const { - if (item.empty()) return 0; // Empty strings are not inserted into the sketch. + if (item.empty()) { + return 0; // Empty strings are not inserted into the sketch. + } return get_estimate(item.c_str(), item.length()); } @@ -176,7 +180,9 @@ void count_min_sketch::update(int64_t item, W weight) { template void count_min_sketch::update(const std::string& item, W weight) { - if (item.empty()) return; + if (item.empty()) { + return; + } update(item.c_str(), item.length(), weight); } @@ -201,7 +207,9 @@ W count_min_sketch::get_upper_bound(int64_t item) const {return get_upper_b template W count_min_sketch::get_upper_bound(const std::string& item) const { - if (item.empty()) return 0; // Empty strings are not inserted into the sketch. + if (item.empty()) { + return 0; // Empty strings are not inserted into the sketch. + } return get_upper_bound(item.c_str(), item.length()); } @@ -218,7 +226,9 @@ W count_min_sketch::get_lower_bound(int64_t item) const {return get_lower_b template W count_min_sketch::get_lower_bound(const std::string& item) const { - if (item.empty()) return 0; // Empty strings are not inserted into the sketch. + if (item.empty()) { + return 0; // Empty strings are not inserted into the sketch. + } return get_lower_bound(item.c_str(), item.length()); } @@ -290,7 +300,9 @@ void count_min_sketch::serialize(std::ostream& os) const { write(os, nhashes); write(os, seed_hash); write(os, unused8); - if (is_empty()) return; // sketch is empty, no need to write further bytes. + if (is_empty()) { + return; // sketch is empty, no need to write further bytes. + } // Long 2 write(os, _total_weight); @@ -327,7 +339,9 @@ auto count_min_sketch::deserialize(std::istream& is, uint64_t seed, const A } count_min_sketch c(nhashes, nbuckets, seed, allocator); const bool is_empty = (flags_byte & (1 << flags::IS_EMPTY)) > 0; - if (is_empty == 1) return c; // sketch is empty, no need to read further. + if (is_empty == 1) { + return c; // sketch is empty, no need to read further. + } // Set the sketch weight and read in the sketch values const auto weight = read(is); @@ -373,7 +387,9 @@ auto count_min_sketch::serialize(unsigned header_size_bytes) const -> vecto ptr += copy_to_mem(nhashes, ptr); ptr += copy_to_mem(seed_hash, ptr); ptr += copy_to_mem(null_characters_8, ptr); - if (is_empty()) return bytes; // sketch is empty, no need to write further bytes. + if (is_empty()) { + return bytes; // sketch is empty, no need to write further bytes. + } // Long 2 const W t_weight = _total_weight; @@ -423,7 +439,9 @@ auto count_min_sketch::deserialize(const void* bytes, size_t size, uint64_t } count_min_sketch c(nhashes, nbuckets, seed, allocator); const bool is_empty = (flags_byte & (1 << flags::IS_EMPTY)) > 0; - if (is_empty) return c; // sketch is empty, no need to read further. + if (is_empty) { + return c; // sketch is empty, no need to read further. + } ensure_minimum_memory(size, sizeof(W) * (1 + nbuckets * nhashes)); @@ -449,8 +467,9 @@ string count_min_sketch::to_string() const { // count the number of used entries in the sketch uint64_t num_nonzero = 0; for (const auto entry: _sketch_array) { - if (entry != static_cast(0.0)) + if (entry != static_cast(0.0)) { ++num_nonzero; + } } // Using a temporary stream for implementation here does not comply with AllocatorAwareContainer requirements.