rjwindow
Super simple data structure. A window. Put data into it, if it reaches the max capacity, the oldest items are removed. Blam.
Example
use Window;
let my_data = vec!;
let mut window = new;
window.stack;
window.stack;
window.extend;
assert_eq!;
Use cases?
In a project of mine I use an MCP3008 analog to digital coverter chip to read capacitive soil moisture sensors. I read them every 3 seconds. However, they are sensitive and a single drop of water can cause them to go from a reading of 20 to 900 instantly (in the range of 0 - 1024). So to solve this, I stack the readings onto a window and look at the average of the window! For example:
// example not intended to be rust accurate
let history = new;
loop
Now what I have is the average of the sensors over a specific period of time. Each time the sensor is read (except for the first time) the readings that are averaged are [0-5 ... 3 seconds later ... 0-5] and each value is spaced out by 10 milliseconds. This helps is stablizing the sensors in case little electron fairies produce a weird value from a bad moisture fairy.
But, feel free to use the data structure however you want! Good luck!!