Skip to content

Instantly share code, notes, and snippets.

@sjl
Created November 9, 2012 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sjl/4043824 to your computer and use it in GitHub Desktop.
Save sjl/4043824 to your computer and use it in GitHub Desktop.
; Integers and Longs are equal.
(= (Integer. 1) (Long. 1))
true
; Even negative ones.
(= (Integer. -1) (Long. -1))
true
; When you use them as keys in maps, the maps are still equal.
(= {(Integer. 1) :foo} {(Long. 1) :foo})
true
(= {(Integer. -1) :foo} {(Long. -1) :foo})
true
; When you use positive numbers as keys to sets, they're also equal.
(= #{(Integer. 1)} #{(Long. 1)})
true
; But negative ones aren't. But only in sets. Maps are fine. lol.
(= #{(Integer. -1)} #{(Long. -1)})
false
@sjl
Copy link
Author

sjl commented Nov 9, 2012

hashing is hard.

@sjl
Copy link
Author

sjl commented Nov 9, 2012

Oh and just to laugh in my face:

#{(Integer. -1) (Long. -1)}

complains about a duplicate key. That little shitbag Mr. PersistentHashSet knows those keys are equal but won't let on when comparing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment