in reply to Re: Circular buffer
in thread Circular buffer
The Perl version is also very fast - not as fast as C, but much easier to write!
No, it's practically exactly the same, op for op.
So to implement a FIFO queue in Perl, just push new entries onto the bottom of the Perl array and shift out "oldest" entries from the top.
A circular buffer is a queue (FIFO), but a queue is not necessarily a circular buffer. You didn't provide any indication as to whether the code you posted is a suitable solution for the OP or not.
It turns out the code you (and I) posted does exhibit the same characteristics as a circular buffer. See my reply.
The Perl array also can implement essentially the equivalent of a 'C' doubly linked list. [...] But in Perl you can use splice()
If you can use splice, you don't have a linked list. Linked lists take O(1) to remove a previously found element. splice takes O(N).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Circular buffer
by Marshall (Canon) on Mar 21, 2011 at 05:56 UTC | |
by ikegami (Patriarch) on Mar 21, 2011 at 15:52 UTC |