优化了 还是卡

This commit is contained in:
2026-08-25 21:44:57 +08:00
parent 4f3430e3ad
commit 65799cfc2a
21 changed files with 850 additions and 1224 deletions
+11 -4
View File
@@ -130,8 +130,9 @@ Statistic_State Sliding_Statistics::submit(double value) {
if (!std::isfinite(value)) return state_;
if (size_ == values_.size()) {
if (!trimmed_window_initialized_) {
const double lower = p05_.value();
const double upper = p95_.value();
double lower = p05_.value();
double upper = p95_.value();
if (lower > upper) std::swap(lower, upper);
trimmed_sum_ = 0.0;
for (std::size_t index = 0; index < size_; ++index) {
trimmed_values_[index] = std::clamp(values_[index], lower, upper);
@@ -151,8 +152,11 @@ Statistic_State Sliding_Statistics::submit(double value) {
minimum_.submit(value, sequence_, values_.size());
maximum_.submit(value, sequence_, values_.size());
++sequence_;
double trim_lower = p05_.value();
double trim_upper = p95_.value();
if (trim_lower > trim_upper) std::swap(trim_lower, trim_upper);
const double trimmed = trimmed_window_initialized_
? std::clamp(value, p05_.value(), p95_.value()) : value;
? std::clamp(value, trim_lower, trim_upper) : value;
values_[next_] = value;
trimmed_values_[next_] = trimmed;
sum_ += value;
@@ -161,12 +165,15 @@ Statistic_State Sliding_Statistics::submit(double value) {
next_ = (next_ + 1U) % values_.size();
size_ = std::min(size_ + 1U, values_.size());
const double mean = sum_ / static_cast<double>(size_);
const double quantile_50 = p50_.value();
const double quantile_95 = std::max(quantile_50, p95_.value());
const double quantile_99 = std::max(quantile_95, p99_.value());
state_ = Statistic_State{
size_, value, minimum_.value(), maximum_.value(), mean,
trimmed_sum_ / static_cast<double>(size_),
std::sqrt(std::max(0.0,
squared_sum_ / static_cast<double>(size_) - mean * mean)),
p50_.value(), p95_.value(), p99_.value()};
quantile_50, quantile_95, quantile_99};
return state_;
}