Skip to content

Instantly share code, notes, and snippets.

@mishok13
Last active December 26, 2015 10:59
Show Gist options
  • Save mishok13/7140401 to your computer and use it in GitHub Desktop.
Save mishok13/7140401 to your computer and use it in GitHub Desktop.
Well, I guess Clojure's hash built-in is properly fucked
user> (count (for [x (range -200 200) y (range -200 200)] (hash {:foo x :bar y :baz "what"})))
160000
user> (count (frequencies (for [x (range -200 200) y (range -200 200)] (hash {:foo x :bar y :baz "what"}))))
487
user> (count (frequencies (for [x (range -200 200) y (range -200 200)] (hash [x y "what"]))))
6369
>>> from collections import Counter
>>> c = Counter(hash((x, y, "what")) for x in xrange(-200, 200) for y in xrange(-200, 200))
>>> len(c)
81355
>>> c.most_common(1)
[(-4913880885218588031, 5)]
;; Since Clojure's APersistentMap hashCode implementation is utterly fucked, you can do this:
user> (hash {:foo :foo :bar "haha"})
1023386773
user> (hash {:bar "haha"})
1023386773
user> (hash {0 0 :bar "haha"})
1023386773
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment