CircBuffer
This class is exactly what it sounds like. It uses an array based implementation of a queue to hold a buffer of any kind of object. Internally, it's used as part of the Sensor drift correction system to store data for averaging, but it can realistically be used for anything.
Usage
Initialization and adding/removing:
There are also these other standard functions, that do about what you'd expect:
Finally, you can use the []
operator to access elements. buffer[0]
is the top of the queue, and buffer[buffer.getCount() - 1]
is the bottom.