[erlang-questions] Circular list
yoursurrogategod@REDACTED
yoursurrogategod@REDACTED
Mon Aug 25 02:42:31 CEST 2008
*lol* Finally one of my posts get here ^_^ .
Ok, back on topic.
Here is a link to the man page about the queue module.
http://www.erlang.org/doc/man/queue.html
I found this part interesting.
All operations has an amortized O(1) running time, except len/1, join/
2, split/2 and filter/2 that are O(n). To minimize the size of a queue
minimizing the amount of garbage built by queue operations, the queues
do not contain explicit length information, and that is why len/1 is
O(n). If better performance for this particular operation is
essential, it is easy for the caller to keep track of the length.
Worst case you'll need to tack on a length function that keeps track
of a limit.
On Aug 24, 8:29 pm, "yoursurrogate...@REDACTED"
<yoursurrogate...@REDACTED> wrote:
> Doing the below is pretty inefficient, as Programming Erlang by Joe
> Armstrong pg. 64 mentions.
>
> List ++ [Foo],
>
> I'm curious why doing this doesn't work at all.
>
> 4> L3 = [L2|"F"].
> [["B","C","D","E"],70]
>
> I'm not too keen on how lists work, so this is puzzling to me :) .
>
> On Aug 22, 9:34 am, "Colm Dougan" <colm.dou...@REDACTED> wrote:
>
>
>
> > Hi,
>
> > If I have a list of a fixed size (say 10,000 elements). What is the
> > most efficient way to add a new item to the list and force out the old
> > first element. By most efficient I mostly mean without having to copy
> > the entire list each time, if that is even possible.
>
> > I'm currently doing a double reverse trick, e.g. :
>
> > Eshell V5.6.3 (abort with ^G)
> > 1> L1 = ["A", "B", "C", "D", "E"].
> > ["A","B","C","D","E"]
> > 2> [_ | L2] = L1.
> > ["A","B","C","D","E"]
> > 3> lists:reverse(["F" | lists:reverse(L2)]).
> > ["B","C","D","E","F"]
>
> > Is there a more efficient way? I tried a benchmark and the reverse
> > seems more costly than I expected.
>
> > Colm
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questi...@REDACTED://www.erlang.org/mailman/listinfo/erlang-questions
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questi...@REDACTED://www.erlang.org/mailman/listinfo/erlang-questions
More information about the erlang-questions
mailing list