Version: SMASH-3.1
smash::Average< T > Class Template Reference

#include <average.h>

template<typename T>
class smash::Average< T >

Calculate an average value incrementally.

Template Parameters
TType of the values (should be floating point).

Definition at line 25 of file average.h.

Public Member Functions

 Average ()
 Create a new object to calculate an average. More...
 
void add (T x)
 Add a value x to the set of numbers defining the average. More...
 
average () const
 
uint64_t number_of_values () const
 
void clear ()
 Reset the average to 0. More...
 

Private Attributes

avg_
 Average. More...
 
uint64_t n_
 Sample size. More...
 

Constructor & Destructor Documentation

◆ Average()

template<typename T >
smash::Average< T >::Average ( )
inline

Create a new object to calculate an average.

Definition at line 28 of file average.h.

28 : avg_(0), n_(0) {}
T avg_
Average.
Definition: average.h:50
uint64_t n_
Sample size.
Definition: average.h:52

Member Function Documentation

◆ add()

template<typename T >
void smash::Average< T >::add ( x)
inline

Add a value x to the set of numbers defining the average.

Definition at line 31 of file average.h.

31  {
32  avg_ = (avg_ * n_ + x) / (n_ + 1);
33  n_++;
34  }

◆ average()

template<typename T >
T smash::Average< T >::average ( ) const
inline
Returns
Current average.

Definition at line 37 of file average.h.

37 { return avg_; }

◆ number_of_values()

template<typename T >
uint64_t smash::Average< T >::number_of_values ( ) const
inline
Returns
Number of values used to calculate the average.

Definition at line 40 of file average.h.

40 { return n_; }

◆ clear()

template<typename T >
void smash::Average< T >::clear ( )
inline

Reset the average to 0.

Definition at line 43 of file average.h.

43  {
44  avg_ = 0;
45  n_ = 0;
46  }

Member Data Documentation

◆ avg_

template<typename T >
T smash::Average< T >::avg_
private

Average.

Definition at line 50 of file average.h.

◆ n_

template<typename T >
uint64_t smash::Average< T >::n_
private

Sample size.

Definition at line 52 of file average.h.


The documentation for this class was generated from the following file: