feisty meow concerns codebase  2.140
mathematics::averager< contents > Class Template Reference

Maintains a list of numbers and provides the average for them. More...

#include <averager.h>

Classes

struct  weighted_entry
 structure holding a weighted chunk of the average. More...
 

Public Member Functions

 averager (int entries=100, bool compacting=true)
 creates an averager whose list length is restricted to "entries". More...
 
void add (contents value, int count=1)
 adds a new "value" to the averager, with an optional "count". More...
 
contents average () const
 reports the overall average of the whole list. More...
 
int samples () const
 returns the total number of samples recorded in the average. More...
 
int length () const
 returns the current length of the averages list. More...
 
contents average (int start, int end) const
 reports the average over the range from "start" to "end" inclusive. More...
 
weighted_entry get (int index) const
 accesses the entry stored at the "index" specified. More...
 
void compact ()
 chops off the oldest portion of the averager. More...
 
void check_for_compaction ()
 checks whether the averager needs to be compacted yet or not. More...
 

Detailed Description

template<class contents>
class mathematics::averager< contents >

Maintains a list of numbers and provides the average for them.

The list entries can be weighted if desired. If the list grows too large, the first chunk of the entries is added as a weighted average and the list's size is reduced appropriately.

Definition at line 31 of file averager.h.

Constructor & Destructor Documentation

◆ averager()

template<class contents >
mathematics::averager< contents >::averager ( int  entries = 100,
bool  compacting = true 
)

creates an averager whose list length is restricted to "entries".

if "entries" that is zero, then the maximum length is used. if "compacting" is true, then the entries which need to be removed during a compaction will be added to the list as a weighted average. if it's false, then the unfortunate entries are just eliminated. the first style leads to a more steady state version of the average while the other is more recent history. note that the lowest reasonable value for "entries" is eight due to the compaction algorithm; lower values will work, but the averager will allow the list to grow to eight anyway.

Definition at line 102 of file averager.h.

References mathematics::AVERAGER_SIZE_LIMIT, and basis::negative().

Member Function Documentation

◆ add()

template<class contents >
void mathematics::averager< contents >::add ( contents  value,
int  count = 1 
)

adds a new "value" to the averager, with an optional "count".

Definition at line 133 of file averager.h.

References mathematics::averager< contents >::weighted_entry::count, and mathematics::averager< contents >::weighted_entry::value.

◆ average() [1/2]

template<class contents >
contents mathematics::averager< contents >::average ( ) const
inline

reports the overall average of the whole list.

Definition at line 48 of file averager.h.

References mathematics::averager< contents >::average(), and mathematics::averager< contents >::length().

Referenced by mathematics::averager< contents >::average().

◆ average() [2/2]

template<class contents >
contents mathematics::averager< contents >::average ( int  start,
int  end 
) const

reports the average over the range from "start" to "end" inclusive.

Definition at line 143 of file averager.h.

References bounds_return.

◆ check_for_compaction()

template<class contents >
void mathematics::averager< contents >::check_for_compaction

checks whether the averager needs to be compacted yet or not.

the decision is made according to the maximum allowable size in "entries" passed to the constructor. if "entries" is zero, the maximum allowable size is used instead.

Definition at line 124 of file averager.h.

References mathematics::AVERAGER_SIZE_LIMIT, and basis::minimum().

◆ compact()

template<class contents >
void mathematics::averager< contents >::compact

chops off the oldest portion of the averager.

if this is a compacting style averager, then the older data is coalesced and added as a weighted entry.

Definition at line 111 of file averager.h.

◆ get()

template<class contents >
weighted_entry mathematics::averager< contents >::get ( int  index) const
inline

accesses the entry stored at the "index" specified.

Definition at line 65 of file averager.h.

◆ length()

template<class contents >
int mathematics::averager< contents >::length ( ) const
inline

returns the current length of the averages list.

Definition at line 54 of file averager.h.

Referenced by mathematics::averager< contents >::average().

◆ samples()

template<class contents >
int mathematics::averager< contents >::samples

returns the total number of samples recorded in the average.

Definition at line 160 of file averager.h.


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