Data Structure for storing X days of history of a variable
<p>I have a variable that has a current value but when I change the value it first needs to store the past value in some data structure that will show me the past X many values. </p>

<p>This is to do all kinds of calculations on past values like an average of the most recent values and such. </p>

<p>My only idea was to use a queue for this and since I only need the past X values then I implemented a FixedSizedQueue that would automatically dequeue older values.</p>

<p>Since then I've found out I can't really access a random value in it at least in default implementations of queues it seems. But additionally that if one would make that work they would be slow and need to iterate over all values. </p>

<p>So I'm left wondering is there any way at all to do this efficiently? The only other way I can think off would be to have an array and simply implement some pushing feature that would move all elements by one index position. But that seems overly wasteful. If these are the only two options, which one would be better if I need to access each value in the data structure 20 times each time I change it, and the size would be 50 values stored?</p>

<p>This is a place where performance will matter a great deal since each variable being "recorded" will change at least a million times when iterating over the data I have so don't worry about me doing premature optimization. Thank you, I appreciate it!</p>
