SlidingAverage

Sliding Average Class

SlidingAverage is very simple. You can add values to the list and you can query the average at any time.

Constructors

this
this(size_t window_size)

Constructor

Members

Functions

average
real average()

Returns the current average

clear
void clear()

Resets the average counter to the zero state:

last
T last()

Returns the last value pushed

push
real push(T value)

Pushes another value to the sliding window, overwriting the oldest one if the sliding window has reached its maximum size. Calculates the new average, stores it, and returns it.

Variables

_average
real _average;

Current average value of the whole window

current_size
size_t current_size;

The number of values the sliding window currently contains

index
size_t index;

Index of the value that was updated most recently

window
T[] window;

Sliding window, containing the values of the recent additions

Meta