On Tue, Aug 11, 2009 at 2:31 PM, fft1976 <fft1...@gmail.com> wrote: > On Aug 11, 8:36 am, John Harrop <jharrop...@gmail.com> wrote: > > > System.identityHashCode() and IdentityHashMap. These use a hash that > > respects reference equality. So one in fact can implement one's own > > serialization that is O(n) using O(1) hashmap lookups (and using > reflection, > > and not working if SecurityManager won't let you setAccessible private > > fields and the like, so not in an unsigned applet). > > Good to know, thanks. By the way, hash table operations are O(log N), > because calculating the hash needs to be O(log N), but I'm nitpicking > now.
The time taken to calculate an object's hash depends on that object's class. For a String for instance it is linear in the String's length; for an Integer, it is constant. Furthermore, hashes are often cached (java.lang.String caches its hash for example). So if A and B are objects that share a common reference to an object C in their fields, and use C's hash code in computing their own, C's hash code may be computed only once, and the cost of hashing A and B may be lower than the sum of the cost of hashing only A and the cost of hashing only B. Furthermore, if A and B are serialized again later, their own hashes may not need to be recalculated... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---