4#include "Containers/StaticArray.h"
7
8
9
10
11template <
typename T, int32 ArraySize>
12class FMovingWindowAverageFast
15 FMovingWindowAverageFast()
16 : TotalValues(
static_cast<T>(0))
17 , AverageValue(
static_cast<T>(0))
21 static_assert(ArraySize > 0,
"ArraySize must be greater than zero");
24 void PushValue(T Value)
26 T ValueRemoved =
static_cast<T>(0);
28 const T NumItemsPrev =
static_cast<T>(NumValuesUsed);
30 if (ArraySize == NumValuesUsed)
32 ValueRemoved = ValuesArray[RemoveNextIdx];
33 ValuesArray[RemoveNextIdx] = Value;
34 RemoveNextIdx = (RemoveNextIdx + 1) % ArraySize;
38 ValuesArray[NumValuesUsed] = Value;
42 const T MovingWindowItemsNumCur =
static_cast<T>(NumValuesUsed);
43 TotalValues = TotalValues - ValueRemoved + Value;
44 AverageValue = TotalValues / MovingWindowItemsNumCur;
53 TStaticArray<T, ArraySize> ValuesArray;