2010/3/9 André Ferreira <greis...@gmail.com>:
> Conj adds to the end of a vector in constant time, but rest will not
> return another vector, but a sequence. Converting that sequence into
> another vector will take O(n). If you want queueing behaviour, you
> should use a clojure.lang.PersistentQueue:
> (-> clojure.lang.PersistentQueue/EMPTY (conj 5) (conj 7) pop (conj 8)
> peek)

rest is definately a bad choice, thanks for pointing that out! In this
particular case, it could be replaced with subvec (called with two
arguments: (subvec v 1)) which the docs describe as being "O(1) and
very fast", but since it is precisely the semantics of a queue that I
had in mind, your suggestion is probably better.

Sincerely,
Michał

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to