Merge 'bloom_filter: cleanups' from Kefu Chai

this series applies some random cleanups to bloom_filter. these cleanups were the side products when the author was working on #13314 .

Closes #13315

* github.com:scylladb/scylladb:
  bloom_filter: mark internal help function static
  bloom_filter: add more constness to false positive rate tables
  bloom_filter: use vector::back() when appropriate
This commit is contained in:
Avi Kivity
2023-03-26 19:43:36 +03:00
2 changed files with 6 additions and 8 deletions

View File

@@ -21,7 +21,7 @@ namespace bloom_calculations {
* Each cell (i,j) the false positive rate determined by using i buckets per
* element and j hash functions.
*/
std::vector<std::vector<double>> probs = {
const std::vector<std::vector<double>> probs = {
{1.0}, // dummy row representing 0 buckets per element
{1.0, 1.0}, // dummy row representing 1 buckets per element
{1.0, 0.393, 0.400},
@@ -50,7 +50,7 @@ std::vector<std::vector<double>> probs = {
* The optimal number of hashes for a given number of bits per element.
* These values are automatically calculated from the data above.
*/
std::vector<int> initialize_opt_k() {
static std::vector<int> initialize_opt_k() {
std::vector<int> arr;
arr.resize(probs.size());
@@ -68,6 +68,6 @@ std::vector<int> initialize_opt_k() {
return arr;
}
std::vector<int> opt_k_per_buckets = initialize_opt_k();
const std::vector<int> opt_k_per_buckets = initialize_opt_k();
}
}

View File

@@ -45,8 +45,8 @@ namespace bloom_calculations {
int constexpr min_k = 1;
int constexpr EXCESS = 20;
extern std::vector<std::vector<double>> probs;
extern std::vector<int> opt_k_per_buckets;
extern const std::vector<std::vector<double>> probs;
extern const std::vector<int> opt_k_per_buckets;
/**
* Given the number of buckets that can be used per element, return a
@@ -130,9 +130,7 @@ namespace bloom_calculations {
* lower than this, it will throw an unsupported_operation_exception.
*/
inline double min_supported_bloom_filter_fp_chance() {
int max_buckets = probs.size() - 1;
int max_K = probs[max_buckets].size() - 1;
return probs[max_buckets][max_K];
return probs.back().back();
}
}