Currently this hangs, makes my machine quickly run out of memory and swap.
(clojure.set/intersection #{1 2} (range))
The problem seems to be that count is called on both arguments to find the
smallest set.
Finding the shortest of 2 seqs lazily shouldn't be a problem, but another
problem I can spot would be that contains? should be used only for some
data structures, like hash-set, otherwise I guess "some" could be used,
which would do the right thing, like in:
(some #{1} (range))
1
(some #{2} (range))
2
At this point execution will stop and return the #{1 2} as all elements of
the smallest set have been tested.
Would it be possible and worth the added complication to fix this ?
There could also be some potential performance improvements, for example
removing count might be slightly more efficient when big sets are involved.
I came up with this while trying to solve 4clojure #108 "find the smallest
single number which appears in all of the sequences".
My approach to the 4clojure problem might be wrong altogether, yet I can
imagine removing this limitation could be useful for some real problems too.
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.