2009-03-18-writting circular lists in erlang
Well I have been struggling to find/create a circular buffer(list to be exact) on erlang, but I'm still not satisfied, I have hacked this:
[_P | T ] = lists:reverse(O), N = [ V | lists:reverse(T)],
To insert V in the head and remove P from the tail. But can you see the problem with that: Two list reverse operations, that to me seems like expensive operations, maybe I'm not understanding fully the erlang's lists module but I can't find other way to do this using lists.
I know several other ways to implement circular buffers using arrays, one even might think using queues for what I need this buffer, but I need to remove any index from the buffer so lists makes a lot more sense than any other data structure.
Well I'll be glad if someone enlightens me with another solution EOPcomments powered by Disqus