20#ifndef SIMPLESTATISTICS
21#define SIMPLESTATISTICS
32#define SIMPLESTATISTICS_ELEMENT_FOR_AVOIDING_ERROR_IN_NESTING_GROUPS_IN_DOXYGEN
77 bool full(
void) {
return(
false); }
91 bool full(
void) { *n_ = 0;
return(
true); }
110 unsigned MAXSIZE = std::numeric_limits<unsigned>::max()
128 void reset(
void) { n_=0; minimum_ = T{}; maximum_ = T{}; average_ = T{}; }
133 if ((n_ == MAXSIZE)&&(!ovpol_.full()))
return;
142 if (v<minimum_) minimum_=v;
143 if (v>maximum_) maximum_=v;
144 T onebyn =
static_cast<T
>(1) / n_;
145 average_ = (
static_cast<T
>(1) - onebyn) * average_ + onebyn * v;
154 T
min(
void)
const noexcept {
return(minimum_); }
157 T
max(
void)
const noexcept {
return(maximum_); }
160 T
avg(
void)
const noexcept {
return(average_); }
165 std::ostringstream s;
166 s <<
"stats(" << n_ <<
"): min=" << minimum_ <<
167 ", max=" << maximum_ <<
168 ", avg=" << average_;
175 T minimum_, maximum_, average_;
177 OverflowPolicy ovpol_;
#define RUNTIMEEXCEP(txt)
Raise a runtime exception with the given std::string TXT + additional info.
SSOvPol_IgnoreMoreData(unsigned *n)
Default constructor.
SSOvPol_Reset(unsigned *nd)
Default constructor.
bool full(void)
Reset and force to take the current datum as the first new one.
bool full(void)
Discard any data after full.
Overflow policy for SimpleStats that ignores further data after full.
Overflow policy for SimpleStats that resets dataset & start afresh, if full.
T avg(void) const noexcept
Statistic: Average of the series.
std::string to_string(void) const noexcept
Return a string that describes the statistics collected so far.
SSOvPol_ThrowExc(unsigned *n)
Default constructor.
bool full(void)
Exception when full.
T max(void) const noexcept
Statistic: Maximum of the series.
virtual ~SimpleStats(void)
Destructor.
T min(void) const noexcept
Statistic: Minimum of the series.
SimpleStats(void)
Default constructor: an empty series.
unsigned sampleSize(void) const noexcept
Return the number of values in the series.
void reset(void)
Clear the series and the statistics.
void addDatum(T v)
Add a new value to the series and recompute statistics.
Overflow policy for SimpleStats that throws an exception if dataset is full.
Class that computes some statistics of a series of values of a given type.
@ T
Key in the 3rd half-row.