Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
simplemovingaverage.c
Go to the documentation of this file.
1 class 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 
13  void SimpleMovingAverage(int pSize, T pDefaultValue = 0)
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 
33  T Add(T newSample)
34  {
35  m_Sum = m_Sum - m_Samples[m_Pointer] + newSample;
36  m_Samples[m_Pointer++] = newSample;
37  if (m_Pointer == m_Size)
38  {
39  m_Pointer = 0;
40  }
41 
42  return m_Sum / m_Size;
43  }
44 }
Add
void Add(string name, string value)
Definition: universaltemperaturesource.c:224
array< T >
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10