Dave.
0. At first sight, but I don't know the details indeed, I find strange
your list update routine: since you push a single item at a time (val),
why do you need to remove the front in a loop? But maybe I just miss the
point.
Concerning your question:
1. Do you implement process, esp its input? If yes, consider using a
list as well. There are chances process only needs traversing the data
and thus a list would do the job perfectly. (The core advantage of an
array is instant access to arbitrary items by index. In go, another is
that one can slice them, but we could do that with lists as well.) In
this case, no copy indeed.
2. There is a data structure I used once a long time ago (don't know the
proper name in english, call it "circular array"), which is just an
array which "first" index is not fixed as 0 (or 1). In other words, you
have a moving start pos, which is a field of the structure. Thus,
instead of performing pop-front, one increments start-pos. The trick is
just to add this offet to indices, and to "modulo" len so that higher
indices reach back the beginning of the array. Thus, on writing, this
beginning is automagically reused. (Hope I'm clear, it's easy in
practice and transparent to the client once implemented.) Again, in this
case, no copy needed.
I hope I properly understood what your question is actually about,
Denis
Thanks everyone for your input. I ended up using a generalized ring
structure based on arrays. As I mentioned, I wanted to minimize the
amount of array copying that needed to be done, so I decided to trade
off space and copying complexity. I describe what I did below, in case
this is helpful to someone.
Sweet deal. If you post the code, I'll include it in the tests.