Hi all,

On Tue, Jun 23, 2009 at 4:16 AM, Four of Seventeen <fsevent...@gmail.com>wrote:

>
> On Jun 22, 6:46 pm, "beatle...@gmail.com" <beatle...@gmail.com> wrote:
> > (take 10 (sort (for [x (range 1000000)] (rand)))))
> >
> > Now the problem is the memory usage, as it does not merely uses memory
> > space for 10 items, but it keeps a reference to the entire sequence.
> > If I leave out the sort its all ok, and done lazily.
>
> Sort can't really be lazy without being unbelievably slow.



Selecting the top N out of n items is a O(n*sqrt(N)) operation so it's
linear when n dominates N and thus must beat take + sort. Plus it won't
retain the whole realized seq in memory.
Maybe contrib already has something like that, else sorted-map and rseq are
your friends :-)

hth,

Christophe



-- 
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.blogspot.com/ (en)

--~--~---------~--~----~------------~-------~--~----~
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