C# Class Redzen.Structures.DoubleCircularBufferWithStats

This is a circular buffer of double precision floating point numbers. A circular buffer must be assigned a capacity at construction time. Values can be enqueued indefintely, but when the buffer's capacity is reached the oldest values in it are overwritten, thus the buffer is best thought of as a circular array or buffer. In addition to normal circular buffer behaviour this class has a 'total' variable that maintains the sum total of all values currently in the buffer. Therefore when the buffer reaches capacity and new values overwrite old ones the total is reduced by the value being overwritten and increased by the new value. This allows us to cheaply (in computational terms) maintain a sum total and mean for all values in the buffer. Note that this class isn't made generic because of the lack of operator contraints required to maintain the sum total of contained items. At time of writing there were ways around this limitation but they either had performance implications and/or resulted in ugly code.
Show file Open project: colgreen/Redzen

Public Methods

Method Description
Clear ( ) : void

Clear the buffer and reset the total.

Dequeue ( ) : double

Remove the oldest value from the back end of the buffer and return it.

DoubleCircularBufferWithStats ( int capacity ) : System

Constructs a circular buffer with the specified capacity.

Enqueue ( double item ) : void

Enqueue a new value. This overwrites the oldest value in the buffer if the buffer has reached capacity.

Pop ( ) : double

Pop the most recently added value from the front end of the buffer and return it.

Method Details

Clear() public method

Clear the buffer and reset the total.
public Clear ( ) : void
return void

Dequeue() public method

Remove the oldest value from the back end of the buffer and return it.
public Dequeue ( ) : double
return double

DoubleCircularBufferWithStats() public method

Constructs a circular buffer with the specified capacity.
public DoubleCircularBufferWithStats ( int capacity ) : System
capacity int
return System

Enqueue() public method

Enqueue a new value. This overwrites the oldest value in the buffer if the buffer has reached capacity.
public Enqueue ( double item ) : void
item double
return void

Pop() public method

Pop the most recently added value from the front end of the buffer and return it.
public Pop ( ) : double
return double