Support merging two util::statistics
This commit is contained in:
parent
7751d6fd36
commit
ce4e561cac
1 changed files with 15 additions and 0 deletions
|
|
@ -48,6 +48,9 @@ namespace psemek::util
|
||||||
T min() const { return min_; }
|
T min() const { return min_; }
|
||||||
T max() const { return max_; }
|
T max() const { return max_; }
|
||||||
|
|
||||||
|
template <typename H>
|
||||||
|
friend statistics<H> merge(statistics<H> const & s1, statistics<H> const & s2);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::size_t count_ = 0;
|
std::size_t count_ = 0;
|
||||||
T sum_ = T{0};
|
T sum_ = T{0};
|
||||||
|
|
@ -86,4 +89,16 @@ namespace psemek::util
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
statistics<T> merge(statistics<T> const & s1, statistics<T> const & s2)
|
||||||
|
{
|
||||||
|
statistics<T> result;
|
||||||
|
result.count_ = s1.count_ + s2.count_;
|
||||||
|
result.sum_ = s1.sum_ + s2.sum_;
|
||||||
|
result.sum_sqr_ = s1.sum_sqr_ + s2.sum_sqr_;
|
||||||
|
result.min_ = std::min(s1.min_, s2.min_);
|
||||||
|
result.max_ = std::max(s1.max_, s2.max_);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue