Fork me on GitHub
#clojure-dev
<
2018-07-01
>
Alex Miller (Clojure team)04:07:04

FYI, I’ll be offline next week. Don’t break anything while I’m gone!

🙊 12
🙌 4
😬 8
👋 8
rhansen13:07:27

I’m sorry if this is written down somewhere, but i’ve not been able to find anything. I’m trying to familiarize myself with the compiler, and I’m seeing several classes have hashCode and hasheq fns. What’s the difference between these two? Thanks! (If anyone got some good links for understanding the clojure source code better, I’m very interested).

ghadi16:07:10

hashCode is normal java hashCode semantics, hasheq is clojure's hash where '(1 2 3) and [1 2 3] have the same hash

rhansen18:07:23

Hmm, ok. So hashCode is only used when storing Clojure data in Java collections? Any reason why hashCode doesn’t just use hasheq? Different hash algorithms?

andy.fingerhut20:07:48

Clojure's hashCode return values are consistent with Java's .equals method for Clojure collections that can be .equals to corresponding Java collections.

andy.fingerhut20:07:25

So Clojure PersistentList .hashCode returns the same hash values that a Java ArrayList instance with the same sequence of .equals elements would return.

andy.fingerhut20:07:26

Until Clojure 1.6.0, Clojure's hasheq on lists, vectors, maps, and sets were the same as hashCode. Shortly before Clojure 1.6.0 was released, it was discovered that this choice of hasheq same as hashCode was poor for some relatively common Clojure program use cases where lists/vectors/sets/maps were used as set elements, or keys in maps, and had many hash collisions.

andy.fingerhut20:07:14

At that time, hashed was modified to be different than hasheq for those collections, but hashCode was left consistent with Java equals for when such collections were used in Java libs.

andy.fingerhut20:07:58

Maybe more detail than you want on that change is on this wiki page: https://dev.clojure.org/display/design/Better+hashing

rhansen21:07:17

Great answer, thank you!