libcruft-util/stats.hpp

44 lines
918 B
C++
Raw Normal View History

2012-05-14 16:11:09 +10:00
/*
2018-08-04 15:14:06 +10:00
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
2012-05-14 16:11:09 +10:00
*
* Copyright 2010 Danny Robson <danny@nerdcruft.net>
*/
#ifndef __UTIL_STATS_HPP
#define __UTIL_STATS_HPP
2018-03-22 16:10:06 +11:00
#include <iosfwd>
2012-05-14 16:11:09 +10:00
namespace cruft {
2012-05-14 16:11:09 +10:00
namespace stats {
// Undefined until at least one value has been added.
template <typename T>
struct accumulator {
accumulator ();
void reset (void);
2012-05-14 16:11:09 +10:00
void add (T);
void add (const accumulator<T> &);
size_t count;
2012-05-14 16:11:09 +10:00
T min;
T max;
T sum;
2012-05-14 16:11:09 +10:00
T range (void) const;
T mean (void) const;
2012-05-14 16:11:09 +10:00
};
template <typename T>
std::ostream& operator<< (std::ostream&, const accumulator<T>&);
}
}
#endif