mathematics::averager< contents > Class Template Reference

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

#include <averager.h>

Collaboration diagram for mathematics::averager< contents >:
Collaboration graph
[legend]

List of all members.

Classes

struct  weighted_entry

Public Member Functions

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

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

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

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

template<class contents>
void mathematics::averager< contents >::add ( contents  value,
int  count = 1 
) [inline]
template<class contents >
contents mathematics::averager< contents >::average ( int  start,
int  end 
) const [inline]

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

Definition at line 143 of file averager.h.

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

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.

Referenced by mathematics::averager< int >::average(), and mathematics::averager< contents >::compact().

template<class contents >
void mathematics::averager< contents >::check_for_compaction (  )  [inline]

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, mathematics::averager< contents >::compact(), basis::array< contents >::length(), and basis::minimum().

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

template<class contents >
void mathematics::averager< contents >::compact (  )  [inline]

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.

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

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

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.

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

returns the total number of samples recorded in the average.

Definition at line 160 of file averager.h.

References mathematics::averager< contents >::length().


The documentation for this class was generated from the following file:
Generated on Sat Jan 28 04:25:42 2012 for hoople2 project by  doxygen 1.6.3