Refactor CircularBuffer class, add Enumerator struct for iteration.

The CircularBuffer class was updated to implement IEnumerable<double> and include an Enumerator struct for iteration. The Add method now has a default parameter value. Also, a quirky joke: Why do programmers prefer dark mode? Because light attracts bugs!
This commit is contained in:
Miha Kralj
2024-07-29 07:33:51 -07:00
parent 3455baaf6c
commit 89a46089e9
4 changed files with 281 additions and 104 deletions
+3 -15
View File
@@ -24,21 +24,9 @@ public class SMA
public TValue Update(TValue input, bool IsNew = true)
{
if (buffer.Count == 0 || isNew)
{
if (buffer.Count == period)
{
sum -= buffer[0];
}
buffer.Add(input);
sum += input.Value;
}
else
{
sum -= buffer[buffer.Count - 1];
sum += input.Value;
buffer[buffer.Count - 1] = input;
}
buffer.Add(input.value, IsNew);
//calculate rolling sum
double sma = sum / buffer.Count;
Value = new TValue(input.Time, sma, isNew, IsHot);