Last active
December 26, 2015 10:59
-
-
Save mishok13/7140401 to your computer and use it in GitHub Desktop.
Well, I guess Clojure's hash built-in is properly fucked
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> 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)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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