On Wed, Jun 24, 2009 at 7:53 AM, Richard Newman holyg...@gmail.com wrote:
Even with the optimization, sort somehow beats top for speed. It looks
like top is best used to avoid major memory consumption for long seqs;
if you have the memory and need the speed, sort's better.
This is an
On Wed, Jun 24, 2009 at 1:43 AM, Christophe Grandchristo...@cgrand.net wrote:
On Wed, Jun 24, 2009 at 7:02 AM, Four of Seventeen fsevent...@gmail.com
wrote:
(defn top [n comptr coll]
(let [m (reduce #(assoc %1 %2 true) (sorted-map-by comptr)
(take n coll))]
(keys
On Jun 24, 2:43 am, Christophe Grand christo...@cgrand.net wrote:
On Wed, Jun 24, 2009 at 7:53 AM, Richard Newman holyg...@gmail.com wrote:
Even with the optimization, sort somehow beats top for speed. It looks
like top is best used to avoid major memory consumption for long seqs;
if
On Jun 24, 12:28 pm, Four of Seventeen fsevent...@gmail.com wrote:
user= (defmacro nanotime [ body] `(let [start (System/nanotime)]
~...@body (- (System/nanotime) start)))
#'user/nanotime
user= (defmacro nanotime [ body] `(let [start# (System/nanotime)]
~...@body (- (System/nanotime)
I don't know if it has an official name but basically it's a modified
tree-sort: for each item you insert a value in a sorted coll of size N and
remove one item from this sorted coll, both ops are O(sqrt(N)) thus
O(n*sqrt(N)) for processing an input whose length is n.
I'm away from a REPL but I
(assoc % (dec n)) should read: (assoc % min (dec n))
2009/6/23 Christophe Grand christo...@cgrand.net
I don't know if it has an official name but basically it's a modified
tree-sort: for each item you insert a value in a sorted coll of size N and
remove one item from this sorted coll, both
On Jun 23, 2009, at 1:47 AM, Christophe Grand wrote:
I don't know if it has an official name but basically it's a
modified tree-sort: for each item you insert a value in a sorted
coll of size N and remove one item from this sorted coll, both ops
are O(sqrt(N)) thus O(n*sqrt(N)) for
On Jun 23, 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 100)] (rand)
Now the problem is the memory usage, as it does not merely uses memory
space for 10 items, but it keeps
Let N be the total number of elements in your collection (e.g.
1000,000), and n the number of elements that you want to take out of
this collection (e.g 10).
By sorting the collection of N elements you spend N log N time. By
repeatedly adding an to the small collection and removing the minimum
On Jun 23, 7:36 am, Christophe Grand christo...@cgrand.net wrote:
Hi all,
On Tue, Jun 23, 2009 at 4:16 AM, Four of Seventeen
fsevent...@gmail.comwrote:
On Jun 22, 6:46 pm, beatle...@gmail.com beatle...@gmail.com wrote:
(take 10 (sort (for [x (range 100)] (rand)
Now the
Jules,
On Jun 23, 2009, at 2:25 AM, Jules wrote:
Let N be the total number of elements in your collection (e.g.
1,000,000), and n the number of elements that you want to take out of
this collection (e.g 10).
By sorting the collection of N elements you spend N log N time. By
repeatedly
On Tue, Jun 23, 2009 at 10:14 AM, Daniel Lyons fus...@storytotell.orgwrote:
I have to admit I don't really understand your code, so my apologies if
I've missed something obvious.
I think if you consider each element of N and do an operation that costs
sqrt(N) with it, you'd arrive at
A further optimization would be to keep track of the lowest value in
your keep set. A simple compare against that value will eliminate
many of the add/removes from the keep set.
Brad
On Jun 23, 1:35 am, Christophe Grand christo...@cgrand.net wrote:
On Tue, Jun 23, 2009 at 10:14 AM, Daniel
On Jun 23, 10:46 pm, Bradbev brad.beveri...@gmail.com wrote:
A further optimization would be to keep track of the lowest value in
your keep set. A simple compare against that value will eliminate
many of the add/removes from the keep set.
(defn top [n comptr coll]
(let [m (reduce #(assoc
On Wed, Jun 24, 2009 at 7:02 AM, Four of Seventeen fsevent...@gmail.comwrote:
(defn top [n comptr coll]
(let [m (reduce #(assoc %1 %2 true) (sorted-map-by comptr)
(take n coll))]
(keys
(reduce #(let [t (assoc %1 %2 true)]
(dissoc t (first (last t m
Dear all,
I really love programming in Clojure, and have done so for the past
couple of months, building my company's software recommendation engine
in Clojure (not in production yet), which I originally wrote in Ruby.
However I have run into the following a memory problem, which actually
was
Does anyone know how to sort and avoid large memory consumptions?
well, presumably the sort needs to look at all the data in order to be
able to sort it, no?! so it is kinda just a tough cookie reality that
the memory will be used.
on the other hand, maybe you can do some form of the
On Jun 22, 6:46 pm, beatle...@gmail.com beatle...@gmail.com wrote:
(take 10 (sort (for [x (range 100)] (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
Hi all,
On Tue, Jun 23, 2009 at 4:16 AM, Four of Seventeen fsevent...@gmail.comwrote:
On Jun 22, 6:46 pm, beatle...@gmail.com beatle...@gmail.com wrote:
(take 10 (sort (for [x (range 100)] (rand)
Now the problem is the memory usage, as it does not merely uses memory
space for
On Jun 22, 2009, at 11:36 PM, Christophe Grand wrote:
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.
Just because I'm curious, I can see how to do max
20 matches
Mail list logo