1 /*------------------------------------------------------------------------
2 Junction: Concurrent data structures in C++
3 Copyright (c) 2016 Jeff Preshing
5 Distributed under the Simplified BSD License.
6 Original location: https://github.com/preshing/junction
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the LICENSE file for more information.
11 ------------------------------------------------------------------------*/
13 #ifndef JUNCTION_AVERAGER_H
14 #define JUNCTION_AVERAGER_H
16 #include <junction/Core.h>
24 std::vector<double> m_values;
28 Averager() : m_finalized(false) {
31 void add(double value) {
32 TURF_ASSERT(!m_finalized);
33 m_values.push_back(value);
36 ureg getNumValues() const {
37 return m_values.size();
40 void finalize(ureg bestValueCount = 0) {
42 std::sort(m_values.begin(), m_values.end());
44 m_values.resize(bestValueCount);
52 for (ureg i = 0; i < m_values.size(); i++) {
55 return sum / m_values.size();
61 } // namespace junction
63 #endif // JUNCTION_AVERAGER_H