Your argument is right and it is a good idea to take advantage of the shared structure to calculate differences. However, it is important to remember that is is just a special case and I don't expect that whenever you want to calculate a difference between two sets, you always compare between the older and newer versions only. In general, I would guess that one would need to compare 2 sets that were never shared in the first place and were created separately. In that case, there is not sharing and this idea wont be applicable. So, if the language must support set-difference then it needs to have two types of implementations anyway, which seems to indicate that it is better not to add such a feature to the language.
Perhaps somebody can write another library for set operations (because it is very frequent these days) that implements this paper (although, I believe this will be easier to implement it at the Java level & not Clojure level) http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.36.9963 Ajay On Wed, Dec 16, 2009 at 8:53 AM, Dragan Djuric <draga...@gmail.com> wrote: > Hi, > > Here's the example of what I meant in the topic title: > > Let's say we have a set s1 that have 3 elements: #{obj1, obj2, obj3} > I add a few elements to it and get s2 #{obj1, obj2, obj3, obj4, obj5} > It is important to notice that, because s2 has been created by > "modifying" s1, it reuses its structure, so these sets are related by > the implementation with the persistent structures. > > Now, I can use difference function to get the difference (obj4, obj5), > but it seems that this function needs to traverse all elements, which > can be heavy if the collection stores thousands of elements. > > I have a hunch that, If the collections are somehow related by the > fact that one collection is used in building the other one, that can > be used as a hint in retrieving the difference. Is something like this > possible in the current implementation and how to do it? I don't mind > accessing persistent collections-related implementation-specific code. > > -- > 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<clojure%2bunsubscr...@googlegroups.com> > 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 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