In general, straight equality is efficient for Clojure data
structures.  For example, the equals() implementation for sets checks
type, size, and hash code before examining the set elements.
Determining that two sets are equal is still O(n), but determining
that they are NOT equal is usually O(1).

As for accessing the shared structure, that's definitely not trivial,
and would require digging into the Java sources.

-SS


On Dec 16, 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
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to