On Mar 7, 3:44 pm, Mark Engelberg <mark.engelb...@gmail.com> wrote:
> Here's why it would be useful to have the option of hash maps that use
> identity...
>
> Let's say my keys are rather long lists. Equality comparison will be
> slow. But if I know that the keys are always the exact same long
> lists (perhaps because I traversed the key sequence to find a key with
> a certain property, and then am updating with that precise key as one
> example), then I can save lots of time by using an identity
> comparison.
>
Identity is tested first in equality, if identical, equal, full stop.
So if you are using identical and unique collections as keys you'll
find them without a value-by-value comparison. If they are not
present, it's unlikely you'll get a matching hashCode and a matching
count and a matching long prefix from a mismatch.
> It's an efficiency issue.
I don't think so. Identity keys are most often needed e.g. when you
are trying to save/restore object graphs and need to know that you've
already seen a particular object perhaps equal to another non-
identical object in the same graph, or otherwise tracking object
identity for synchronization with an external system. Using
IdentityHashMap as an implementation detail in these situations is
perfectly fine. I don't see a compelling argument for clojure to offer
identity-based collections.
Rich
--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---