📤 Get By Brute
Returns the average of the N last added data points requested.
If the number of requested points exceed the array size, it will return the average of points already added.
⚠ Pay attention to how get_by_brute is significantly slower than the pure get function. If you are looking for a more efficient solution, search for the partial average concept in this library.
📝 Syntax
TypeOfArray get_by_brute(size_t n_points)
🔮 Example
// This will create an MovingAverage of size 4 and int type
// Array: 0 0 0 0
MovingAveragePlus<int> intAverage(4);
// Array: 8 0 0 0
intAverage.push(8);
// Array: 8 8 0 0
intAverage.push(8);
// Array: 4 8 8 0
intAverage.push(4);
// Array: 4 4 8 8
intAverage.push(4);
// Returns the average
// Value: (8 + 8 + 4 + 4) / 4 = 6
intAverage.get_by_brute(4);
// Value: (4 + 4) / 2 = 4
intAverage.get_by_brute(2);
⏱ Complexity
Linear (O(n)) in the data points requested.