diff options
author | Ivan Korostelev <ivan.korostelev@gmail.com> | 2022-02-10 16:46:41 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:41 +0300 |
commit | b5e813096385b2d9e16b572711fec5bf2eb5058d (patch) | |
tree | 49e222ea1c5804306084bb3ae065bb702625360f /library/cpp/histogram | |
parent | f3a52f9d3e18d1159abbc85fa65eeda69d971657 (diff) | |
download | ydb-b5e813096385b2d9e16b572711fec5bf2eb5058d.tar.gz |
Restoring authorship annotation for Ivan Korostelev <ivan.korostelev@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/histogram')
-rw-r--r-- | library/cpp/histogram/adaptive/adaptive_histogram.cpp | 180 | ||||
-rw-r--r-- | library/cpp/histogram/adaptive/adaptive_histogram.h | 54 | ||||
-rw-r--r-- | library/cpp/histogram/adaptive/auto_histogram.h | 8 | ||||
-rw-r--r-- | library/cpp/histogram/adaptive/histogram.h | 4 | ||||
-rw-r--r-- | library/cpp/histogram/adaptive/multi_histogram.h | 14 |
5 files changed, 130 insertions, 130 deletions
diff --git a/library/cpp/histogram/adaptive/adaptive_histogram.cpp b/library/cpp/histogram/adaptive/adaptive_histogram.cpp index 8cc0323135..cbfc494021 100644 --- a/library/cpp/histogram/adaptive/adaptive_histogram.cpp +++ b/library/cpp/histogram/adaptive/adaptive_histogram.cpp @@ -1,12 +1,12 @@ #include "adaptive_histogram.h" -#include <util/generic/algorithm.h> +#include <util/generic/algorithm.h> #include <util/generic/yexception.h> #include <util/generic/ymath.h> #include <util/string/printf.h> -#include <util/system/backtrace.h> - +#include <util/system/backtrace.h> + namespace NKiwiAggr { TAdaptiveHistogram::TAdaptiveHistogram(size_t intervals, ui64 id, TQualityFunction qualityFunc) : Id(id) @@ -64,7 +64,7 @@ namespace NKiwiAggr { } TWeightedValue weightedValue(value, weight); Add(weightedValue, true); - PrecomputedBins.clear(); + PrecomputedBins.clear(); } void TAdaptiveHistogram::Merge(const THistogram& histo, double multiplier) { @@ -294,25 +294,25 @@ namespace NKiwiAggr { if (bound > MaxValue) { return 0.0; } - - if (!PrecomputedBins.empty()) { - return GetSumAboveBoundImpl( - bound, - PrecomputedBins, - LowerBound(PrecomputedBins.begin(), PrecomputedBins.end(), TFastBin{bound, -1.0, 0, 0}), + + if (!PrecomputedBins.empty()) { + return GetSumAboveBoundImpl( + bound, + PrecomputedBins, + LowerBound(PrecomputedBins.begin(), PrecomputedBins.end(), TFastBin{bound, -1.0, 0, 0}), [](const auto& it) { return it->SumAbove; }); - } else { - return GetSumAboveBoundImpl( - bound, - Bins, - Bins.lower_bound(TWeightedValue(bound, -1.0)), - [this](TPairSet::const_iterator rightBin) { - ++rightBin; - double sum = 0; - for (TPairSet::const_iterator it = rightBin; it != Bins.end(); ++it) { - sum += it->second; - } - return sum; + } else { + return GetSumAboveBoundImpl( + bound, + Bins, + Bins.lower_bound(TWeightedValue(bound, -1.0)), + [this](TPairSet::const_iterator rightBin) { + ++rightBin; + double sum = 0; + for (TPairSet::const_iterator it = rightBin; it != Bins.end(); ++it) { + sum += it->second; + } + return sum; }); } } @@ -327,24 +327,24 @@ namespace NKiwiAggr { if (bound > MaxValue) { return Sum; } - - if (!PrecomputedBins.empty()) { - return GetSumBelowBoundImpl( - bound, - PrecomputedBins, - LowerBound(PrecomputedBins.begin(), PrecomputedBins.end(), TFastBin{bound, -1.0, 0, 0}), + + if (!PrecomputedBins.empty()) { + return GetSumBelowBoundImpl( + bound, + PrecomputedBins, + LowerBound(PrecomputedBins.begin(), PrecomputedBins.end(), TFastBin{bound, -1.0, 0, 0}), [](const auto& it) { return it->SumBelow; }); - } else { - return GetSumBelowBoundImpl( - bound, - Bins, - Bins.lower_bound(TWeightedValue(bound, -1.0)), - [this](TPairSet::const_iterator rightBin) { - double sum = 0; - for (TPairSet::iterator it = Bins.begin(); it != rightBin; ++it) { - sum += it->second; - } - return sum; + } else { + return GetSumBelowBoundImpl( + bound, + Bins, + Bins.lower_bound(TWeightedValue(bound, -1.0)), + [this](TPairSet::const_iterator rightBin) { + double sum = 0; + for (TPairSet::iterator it = Bins.begin(); it != rightBin; ++it) { + sum += it->second; + } + return sum; }); } } @@ -583,55 +583,55 @@ namespace NKiwiAggr { Add(newBin, false); } - void TAdaptiveHistogram::PrecomputePartialSums() { - PrecomputedBins.clear(); - PrecomputedBins.reserve(Bins.size()); - double currentSum = 0; - for (const auto& bin : Bins) { - PrecomputedBins.emplace_back(bin.first, bin.second, currentSum, Sum - currentSum - bin.second); - currentSum += bin.second; - } - } - - template <typename TBins, typename TGetSumAbove> - double TAdaptiveHistogram::GetSumAboveBoundImpl(double bound, const TBins& bins, typename TBins::const_iterator rightBin, const TGetSumAbove& getSumAbove) const { - typename TBins::value_type left(MinValue, 0.0); - typename TBins::value_type right(MaxValue, 0.0); - if (rightBin != bins.end()) { - right = *rightBin; - } - if (rightBin != bins.begin()) { - typename TBins::const_iterator leftBin = rightBin; - --leftBin; - left = *leftBin; - } - double sum = (right.second / 2) + ((right.first == left.first) ? ((left.second + right.second) / 2) : (((left.second + right.second) / 2) * (right.first - bound) / (right.first - left.first))); - if (rightBin == bins.end()) { - return sum; - } - sum += getSumAbove(rightBin); - return sum; - } - - template <typename TBins, typename TGetSumBelow> - double TAdaptiveHistogram::GetSumBelowBoundImpl(double bound, const TBins& bins, typename TBins::const_iterator rightBin, const TGetSumBelow& getSumBelow) const { - typename TBins::value_type left(MinValue, 0.0); - typename TBins::value_type right(MaxValue, 0.0); - if (rightBin != bins.end()) { - right = *rightBin; - } - if (rightBin != bins.begin()) { - typename TBins::const_iterator leftBin = rightBin; - --leftBin; - left = *leftBin; - } - double sum = (left.second / 2) + ((right.first == left.first) ? ((left.second + right.second) / 2) : (((left.second + right.second) / 2) * (bound - left.first) / (right.first - left.first))); - if (rightBin == bins.begin()) { - return sum; - } - --rightBin; - sum += getSumBelow(rightBin); - return sum; - } - + void TAdaptiveHistogram::PrecomputePartialSums() { + PrecomputedBins.clear(); + PrecomputedBins.reserve(Bins.size()); + double currentSum = 0; + for (const auto& bin : Bins) { + PrecomputedBins.emplace_back(bin.first, bin.second, currentSum, Sum - currentSum - bin.second); + currentSum += bin.second; + } + } + + template <typename TBins, typename TGetSumAbove> + double TAdaptiveHistogram::GetSumAboveBoundImpl(double bound, const TBins& bins, typename TBins::const_iterator rightBin, const TGetSumAbove& getSumAbove) const { + typename TBins::value_type left(MinValue, 0.0); + typename TBins::value_type right(MaxValue, 0.0); + if (rightBin != bins.end()) { + right = *rightBin; + } + if (rightBin != bins.begin()) { + typename TBins::const_iterator leftBin = rightBin; + --leftBin; + left = *leftBin; + } + double sum = (right.second / 2) + ((right.first == left.first) ? ((left.second + right.second) / 2) : (((left.second + right.second) / 2) * (right.first - bound) / (right.first - left.first))); + if (rightBin == bins.end()) { + return sum; + } + sum += getSumAbove(rightBin); + return sum; + } + + template <typename TBins, typename TGetSumBelow> + double TAdaptiveHistogram::GetSumBelowBoundImpl(double bound, const TBins& bins, typename TBins::const_iterator rightBin, const TGetSumBelow& getSumBelow) const { + typename TBins::value_type left(MinValue, 0.0); + typename TBins::value_type right(MaxValue, 0.0); + if (rightBin != bins.end()) { + right = *rightBin; + } + if (rightBin != bins.begin()) { + typename TBins::const_iterator leftBin = rightBin; + --leftBin; + left = *leftBin; + } + double sum = (left.second / 2) + ((right.first == left.first) ? ((left.second + right.second) / 2) : (((left.second + right.second) / 2) * (bound - left.first) / (right.first - left.first))); + if (rightBin == bins.begin()) { + return sum; + } + --rightBin; + sum += getSumBelow(rightBin); + return sum; + } + } diff --git a/library/cpp/histogram/adaptive/adaptive_histogram.h b/library/cpp/histogram/adaptive/adaptive_histogram.h index 2c057ff2a1..fa8f48433f 100644 --- a/library/cpp/histogram/adaptive/adaptive_histogram.h +++ b/library/cpp/histogram/adaptive/adaptive_histogram.h @@ -17,27 +17,27 @@ namespace NKiwiAggr { private: using TPairSet = TSet<TWeightedValue>; - struct TFastBin { - // these names are for compatibility with TWeightedValue - double first; - double second; - // both sums do not include current bin - double SumBelow; - double SumAbove; - + struct TFastBin { + // these names are for compatibility with TWeightedValue + double first; + double second; + // both sums do not include current bin + double SumBelow; + double SumAbove; + TFastBin(double first_, double second_, double sumBelow = 0, double sumAbove = 0) - : first(first_) - , second(second_) - , SumBelow(sumBelow) - , SumAbove(sumAbove) - { - } - + : first(first_) + , second(second_) + , SumBelow(sumBelow) + , SumAbove(sumAbove) + { + } + bool operator<(const TFastBin& rhs) const { - return first < rhs.first; - } - }; - + return first < rhs.first; + } + }; + ui64 Id; double MinValue; double MaxValue; @@ -48,7 +48,7 @@ namespace NKiwiAggr { TQualityFunction CalcQuality; TVector<TFastBin> PrecomputedBins; - + public: TAdaptiveHistogram(size_t intervals, ui64 id = 0, TQualityFunction qualityFunc = CalcWeightQuality); TAdaptiveHistogram(const THistogram& histo, size_t defaultIntervals = DEFAULT_INTERVALS, ui64 defaultId = 0, TQualityFunction qualityFunc = nullptr); @@ -88,18 +88,18 @@ namespace NKiwiAggr { double CalcLowerBoundSafe(double sum) final; void PrecomputePartialSums() final; - + private: void FromIHistogram(IHistogram* histo); void Add(const TWeightedValue& weightedValue, bool initial); void Erase(double value); void Shrink(); - - template <typename TBins, typename TGetSumAbove> - double GetSumAboveBoundImpl(double bound, const TBins& bins, typename TBins::const_iterator rightBin, const TGetSumAbove& getSumAbove) const; - - template <typename TBins, typename TGetSumBelow> - double GetSumBelowBoundImpl(double bound, const TBins& bins, typename TBins::const_iterator rightBin, const TGetSumBelow& getSumBelow) const; + + template <typename TBins, typename TGetSumAbove> + double GetSumAboveBoundImpl(double bound, const TBins& bins, typename TBins::const_iterator rightBin, const TGetSumAbove& getSumAbove) const; + + template <typename TBins, typename TGetSumBelow> + double GetSumBelowBoundImpl(double bound, const TBins& bins, typename TBins::const_iterator rightBin, const TGetSumBelow& getSumBelow) const; }; template <TQualityFunction QualityFunction> diff --git a/library/cpp/histogram/adaptive/auto_histogram.h b/library/cpp/histogram/adaptive/auto_histogram.h index 4c2c6b8bde..9fdf0b9abe 100644 --- a/library/cpp/histogram/adaptive/auto_histogram.h +++ b/library/cpp/histogram/adaptive/auto_histogram.h @@ -139,10 +139,10 @@ namespace NKiwiAggr { virtual double CalcLowerBoundSafe(double sum) { return HistogramImpl->CalcLowerBoundSafe(sum); } - - virtual void PrecomputePartialSums() { - return HistogramImpl->PrecomputePartialSums(); - } + + virtual void PrecomputePartialSums() { + return HistogramImpl->PrecomputePartialSums(); + } }; } diff --git a/library/cpp/histogram/adaptive/histogram.h b/library/cpp/histogram/adaptive/histogram.h index 639a9c0445..360fd9a693 100644 --- a/library/cpp/histogram/adaptive/histogram.h +++ b/library/cpp/histogram/adaptive/histogram.h @@ -57,8 +57,8 @@ namespace NKiwiAggr { double GetValueAtPercentileSafe(double percentile) { return CalcUpperBoundSafe(percentile * GetSum()); } - - // Histogram implementation is supposed to clear all precomputed values() if Add() is called after PrecomputePartialSums() + + // Histogram implementation is supposed to clear all precomputed values() if Add() is called after PrecomputePartialSums() virtual void PrecomputePartialSums() { } }; diff --git a/library/cpp/histogram/adaptive/multi_histogram.h b/library/cpp/histogram/adaptive/multi_histogram.h index af5778718f..41caac5ba6 100644 --- a/library/cpp/histogram/adaptive/multi_histogram.h +++ b/library/cpp/histogram/adaptive/multi_histogram.h @@ -5,7 +5,7 @@ #include <library/cpp/histogram/adaptive/protos/histo.pb.h> -#include <util/generic/hash.h> +#include <util/generic/hash.h> #include <util/generic/ptr.h> #include <utility> @@ -119,12 +119,12 @@ namespace NKiwiAggr { it->second->ToProto(*histo); } } - - void PrecomputePartialSums() { - for (auto& it : Histograms) { - it.second->PrecomputePartialSums(); - } - } + + void PrecomputePartialSums() { + for (auto& it : Histograms) { + it.second->PrecomputePartialSums(); + } + } }; template <class TMerger, class TSomeMultiHistogram> |