Statistics  1.0.0
A C++17 for profiling and constant time statistical calculation
Statistics< T > Class Template Reference

Keeps a simple average of a series of measurements. More...

#include <statistics.h>

Public Types

using T2 = decltype(T{} *T{})
 

Public Member Functions

 Statistics ()
 Default Constructor.
 
 Statistics (T measurement)
 Constructor. More...
 
 Statistics (std::initializer_list< T > init)
 Construct from initializer list. More...
 
template<class InputIt >
 Statistics (InputIt first, InputIt last)
 Constructor from input iterators. More...
 
void clear () noexcept
 
size_t count () const noexcept
 Measurement count. More...
 
Statisticsinsert (const T &measurement) noexcept
 Insert a measurement into the population. More...
 
template<class InputIt >
Statisticsinsert (const InputIt &first, const InputIt &last) noexcept
 Insert measurements into the population. More...
 
mean () const noexcept
 Value of the mean. More...
 
min () const noexcept
 Returns minimum sampled value. More...
 
max () const noexcept
 Returns maximum sampled value. More...
 
sum () const noexcept
 Sum of the samples. More...
 
T2 sumOfSquares () const noexcept
 Returns the sum of squares of all measurements. More...
 
auto variance () const noexcept
 Calculates the variance of the population. More...
 
standardDeviation () const noexcept
 Calculates the standard deviation of the population. More...
 
Statisticsoperator+= (const T &measurement) noexcept
 Returns the average updated with the given measurement. More...
 
Statisticsoperator+= (const Statistics &rhs) noexcept
 Returns the average updated with the given measurement. More...
 

Friends

template<class U >
Statistics< U > operator+ (const Statistics< U > &lhs, const T &rhs) noexcept
 
template<class U >
Statistics< U > operator+ (const Statistics< U > &lhs, const Statistics< U > &rhs) noexcept
 
template<class U >
bool operator== (const Statistics< U > &lhs, const Statistics< U > &rhs) noexcept
 
template<class U >
bool operator!= (const Statistics< U > &lhs, const Statistics< U > &rhs) noexcept
 
template<class U >
bool operator< (const Statistics< U > &lhs, const Statistics< U > &rhs) noexcept
 
template<class U >
bool operator<= (const Statistics< U > &lhs, const Statistics< U > &rhs) noexcept
 
template<class U >
bool operator> (const Statistics< U > &lhs, const Statistics< U > &rhs) noexcept
 
template<class U >
bool operator>= (const Statistics< U > &lhs, const Statistics< U > &rhs) noexcept
 

Detailed Description

template<class T>
class Statistics< T >

Keeps a simple average of a series of measurements.


Constructor & Destructor Documentation

◆ Statistics() [1/3]

template<class T >
Statistics< T >::Statistics ( measurement)
inlineexplicit

Constructor.

O(1) complexity

Parameters
[in]measurementInitial measurement

◆ Statistics() [2/3]

template<class T >
Statistics< T >::Statistics ( std::initializer_list< T >  init)
inline

Construct from initializer list.

O(N) complexity.

Parameters
[in]initinitializer list containing the population

◆ Statistics() [3/3]

template<class T >
template<class InputIt >
Statistics< T >::Statistics ( InputIt  first,
InputIt  last 
)
inlineexplicit

Constructor from input iterators.

O(1) complexity

Parameters
[in]seedStarting value for the average. Defaults to 0.

Member Function Documentation

◆ count()

template<class T >
size_t Statistics< T >::count ( ) const
inlinenoexcept

Measurement count.

O(1) complexity.

Returns
The number of measurements taken

◆ insert() [1/2]

template<class T >
template<class InputIt >
Statistics& Statistics< T >::insert ( const InputIt &  first,
const InputIt &  last 
)
inlinenoexcept

Insert measurements into the population.

O(N) complexity.

Parameters
[in]firstbegin iterator
[in]lastend iterator
Returns
Reference to this

◆ insert() [2/2]

template<class T >
Statistics& Statistics< T >::insert ( const T &  measurement)
inlinenoexcept

Insert a measurement into the population.

O(1) complexity. Equivalent to +=.

Parameters
[in]measurementMeasurement to add to the population
Returns
Reference to this

◆ max()

template<class T >
T Statistics< T >::max ( ) const
inlinenoexcept

Returns maximum sampled value.

O(1) complexity.

◆ mean()

template<class T >
T Statistics< T >::mean ( ) const
inlinenoexcept

Value of the mean.

O(1) complexity. Returns 0 if no measurements have been taken.

Returns
Current value of the average

◆ min()

template<class T >
T Statistics< T >::min ( ) const
inlinenoexcept

Returns minimum sampled value.

O(1) complexity.

◆ operator+=() [1/2]

template<class T >
Statistics& Statistics< T >::operator+= ( const Statistics< T > &  rhs)
inlinenoexcept

Returns the average updated with the given measurement.

O(1) complexity.

Parameters
[in]measurementvalue to add to the average.
Returns
Reference to this.

◆ operator+=() [2/2]

template<class T >
Statistics& Statistics< T >::operator+= ( const T &  measurement)
inlinenoexcept

Returns the average updated with the given measurement.

O(1) complexity.

Parameters
[in]measurementvalue to add to the average.
Returns
Reference to this.

◆ standardDeviation()

template<class T >
T Statistics< T >::standardDeviation ( ) const
inlinenoexcept

Calculates the standard deviation of the population.

O(1) complexity.

Returns
standard deviation

◆ sum()

template<class T >
T Statistics< T >::sum ( ) const
inlinenoexcept

Sum of the samples.

O(1) complexity.

Returns
The sum of all sampled values

◆ sumOfSquares()

template<class T >
T2 Statistics< T >::sumOfSquares ( ) const
inlinenoexcept

Returns the sum of squares of all measurements.

O(1) complexity.

Returns
T2

◆ variance()

template<class T >
auto Statistics< T >::variance ( ) const
inlinenoexcept

Calculates the variance of the population.

O(1) complexity.

Returns
variance

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