#include <averager.h>
Collaboration diagram for averager< contents >:

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. | |
Classes | |
| struct | weighted_entry |
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 28 of file averager.h.
| 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 38 of file averager.cpp.
References AVERAGER_SIZE_LIMIT, and negative().
| void averager< contents >::add | ( | contents | value, | |
| int | count = 1 | |||
| ) |
adds a new "value" to the averager, with an optional "count".
Definition at line 69 of file averager.cpp.
References averager< contents >::check_for_compaction(), averager< contents >::weighted_entry::count, and averager< contents >::weighted_entry::value.
| contents averager< contents >::average | ( | ) | const [inline] |
reports the overall average of the whole list.
Definition at line 45 of file averager.h.
Referenced by averager< int >::average(), averager< contents >::compact(), and item_statistics::text_form().
| int averager< contents >::samples | ( | ) | const |
returns the total number of samples recorded in the average.
Definition at line 96 of file averager.cpp.
References averager< contents >::weighted_entry::count, averager< contents >::get(), and averager< contents >::length().
Referenced by item_statistics::text_form().
| int averager< contents >::length | ( | ) | const [inline] |
returns the current length of the averages list.
Definition at line 51 of file averager.h.
Referenced by averager< int >::average(), averager< contents >::average(), averager< contents >::compact(), and averager< contents >::samples().
| contents averager< contents >::average | ( | int | start, | |
| int | end | |||
| ) | const |
reports the average over the range from "start" to "end" inclusive.
Definition at line 79 of file averager.cpp.
References bounds_return, averager< contents >::weighted_entry::count, averager< contents >::get(), and averager< contents >::length().
| weighted_entry averager< contents >::get | ( | int | index | ) | const [inline] |
accesses the entry stored at the "index" specified.
Definition at line 62 of file averager.h.
Referenced by averager< contents >::average(), and averager< contents >::samples().
| void 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 47 of file averager.cpp.
References averager< contents >::average(), array< contents >::length(), averager< contents >::length(), and array< contents >::zap().
Referenced by averager< contents >::check_for_compaction().
| void 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 60 of file averager.cpp.
References AVERAGER_SIZE_LIMIT, averager< contents >::compact(), array< contents >::length(), and minimum().
Referenced by averager< contents >::add().
1.5.1