00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00026 #ifndef HH_SENF_Utils_StatisticAccumulator_
00027 #define HH_SENF_Utils_StatisticAccumulator_ 1
00028
00029
00030 #include <math.h>
00031 #include <boost/cstdint.hpp>
00033 namespace senf {
00034
00035 struct StatisticsData
00036 {
00037 StatisticsData( float min_, float avg_, float max_, float stddev_, boost::uint32_t count_)
00038 : min(min_), avg(avg_), max(max_), stddev(stddev_), count(count_){
00039 };
00040 StatisticsData( StatisticsData const & other)
00041 : min(other.min), avg(other.avg), max(other.max), stddev(other.stddev), count(other.count){
00042 };
00043 StatisticsData()
00044 : min(0.0), avg(0.0), max(0.0), stddev(0.0), count(0){
00045 };
00046
00047 float min;
00048 float avg;
00049 float max;
00050 float stddev;
00051 boost::uint32_t count;
00052 };
00053
00068 template <class T>
00069 class StatisticAccumulator
00070 {
00071 public:
00072 StatisticAccumulator();
00073
00074
00075 void clear();
00077
00078 void accumulate(T value);
00080
00082 void setLastAvg(T value);
00084
00087 public:
00088 T min() const;
00090
00091 T max() const;
00093
00094 float avg() const;
00096
00097 float last_avg() const;
00099
00100 float stddev() const;
00102
00103 boost::uint32_t count() const;
00105
00106 void data( StatisticsData & data_) const;
00108
00110 private:
00111 T sum_squared_;
00112 T sum_;
00113 T min_;
00114 T max_;
00115 float last_avg_;
00116 boost::uint32_t count_;
00117
00118
00119 };
00120
00121
00122 typedef StatisticAccumulator<int> StatisticAccumulatorInt;
00123 typedef StatisticAccumulator<float> StatisticAccumulatorFloat;
00124
00125 }
00127
00128 #include "StatisticAccumulator.ct"
00129 #include "StatisticAccumulator.cti"
00130 #endif
00131