mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Enable modernize-std-numbers clang-tidy checker, fix findings
This commit is contained in:
parent
414728cc71
commit
b4cbda4e02
3 changed files with 6 additions and 5 deletions
|
@ -64,7 +64,6 @@ Checks: [-*,
|
||||||
# These are features in newer version of C++ that we don't have
|
# These are features in newer version of C++ that we don't have
|
||||||
# access to yet.
|
# access to yet.
|
||||||
-modernize-use-std-format,
|
-modernize-use-std-format,
|
||||||
-modernize-use-std-numbers,
|
|
||||||
-modernize-use-std-print,
|
-modernize-use-std-print,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <numbers>
|
||||||
|
|
||||||
#include "zeek/Reporter.h"
|
#include "zeek/Reporter.h"
|
||||||
#include "zeek/broker/Data.h"
|
#include "zeek/broker/Data.h"
|
||||||
|
@ -86,13 +87,13 @@ bool BloomFilter::DoUnserializeData(BrokerDataView data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t BasicBloomFilter::M(double fp, size_t capacity) {
|
size_t BasicBloomFilter::M(double fp, size_t capacity) {
|
||||||
double ln2 = std::log(2);
|
double ln2 = std::numbers::ln2;
|
||||||
return std::ceil(-(capacity * std::log(fp) / ln2 / ln2));
|
return std::ceil(-(capacity * std::log(fp) / ln2 / ln2));
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t BasicBloomFilter::K(size_t cells, size_t capacity) {
|
size_t BasicBloomFilter::K(size_t cells, size_t capacity) {
|
||||||
double frac = static_cast<double>(cells) / static_cast<double>(capacity);
|
double frac = static_cast<double>(cells) / static_cast<double>(capacity);
|
||||||
return std::ceil(frac * std::log(2));
|
return std::ceil(frac * std::numbers::ln2);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BasicBloomFilter::Empty() const { return bits->AllZero(); }
|
bool BasicBloomFilter::Empty() const { return bits->AllZero(); }
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <numbers>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "zeek/Reporter.h"
|
#include "zeek/Reporter.h"
|
||||||
|
@ -13,7 +14,7 @@
|
||||||
namespace zeek::probabilistic::detail {
|
namespace zeek::probabilistic::detail {
|
||||||
|
|
||||||
int CardinalityCounter::OptimalB(double error, double confidence) const {
|
int CardinalityCounter::OptimalB(double error, double confidence) const {
|
||||||
double initial_estimate = 2 * (log(1.04) - log(error)) / log(2);
|
double initial_estimate = 2 * (log(1.04) - log(error)) / std::numbers::ln2;
|
||||||
int answer = (int)floor(initial_estimate);
|
int answer = (int)floor(initial_estimate);
|
||||||
|
|
||||||
// k is the number of standard deviations that we have to go to have
|
// k is the number of standard deviations that we have to go to have
|
||||||
|
@ -24,7 +25,7 @@ int CardinalityCounter::OptimalB(double error, double confidence) const {
|
||||||
do {
|
do {
|
||||||
answer++;
|
answer++;
|
||||||
k = pow(2, (answer - initial_estimate) / 2);
|
k = pow(2, (answer - initial_estimate) / 2);
|
||||||
} while ( erf(k / sqrt(2)) < confidence );
|
} while ( erf(k / std::numbers::sqrt2) < confidence );
|
||||||
|
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue