DayZ 1.24
Loading...
Searching...
No Matches
SimpleMovingAverage.c
Go to the documentation of this file.
1class SimpleMovingAverage<Class T>
2{
3 private T m_Sum = 0;
4 private int m_Pointer = 0;
5 private int m_Size = 0;
6 private ref array<T> m_Samples = new array<T>();
7
14 {
15 m_Size = pSize;
16
17 for (int i = 0; i < m_Size; i++)
18 {
19 m_Samples.Insert(pDefaultValue);
20 m_Sum += m_Samples[i];
21 }
22 }
23
34 {
35 m_Sum = m_Sum - m_Samples[m_Pointer] + newSample;
36 m_Samples[m_Pointer++] = newSample;
37 if (m_Pointer == m_Size)
38 m_Pointer = 0;
39
40 return m_Sum / m_Size;
41 }
42}
Super root of all classes in Enforce script.
Definition EnScript.c:11
T Add(T newSample)
Add new value and return average value from buffer.
void SimpleMovingAverage(int pSize, T pDefaultValue=0)
Initialize Simple Moving Average Cyclic Buffer.