Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- user=> (= (byte-array (map byte [1 2 3])) (byte-array (map byte [1 2 3]))) ; not equal
- false
- user=> {(byte-array (map byte [1 2 3])) 1, (byte-array (map byte [1 2 3])) 2, (byte-array (map byte [2 3 4])) 3} ; hashes are the same... THIS TIME
- IllegalArgumentException Duplicate key: (byte-array (map byte [1 2 3])) clojure.lang.PersistentArrayMap.createWithCheck (PersistentArrayMap.java:70)
- user=> (def a (byte-array (map byte [1 2 3]))
- )
- #'user/a
- user=> (def b (byte-array (map byte [1 2 3])))
- #'user/b
- user=> (= a b) ; again, not equal
- false
- user=> (.hashCode a) ; ...different hashes!
- 2137552888
- user=> (.hashCode b)
- 545732387
- user=> {a 1, b 2} ; no complaints from the hash-map constructor
- {#<byte[] [B@7f6877f8> 1, #<byte[] [B@20873723> 2}
- ; I thought maybe the reader was caching the two arrays created in the same expression, but I can't replicate that:
- user=> (map #(.hashCode %) [(byte-array (map byte [1 2 3])) (byte-array (map byte [1 2 3])) (byte-array (map byte [2 3 4]))])
- (1629818866 1211763377 1519652738)
- user=> [(.hashCode (byte-array (map byte [1 2 3]))) (.hashCode (byte-array (map byte [1 2 3]))) (.hashCode (byte-array (map byte [2 3 4])))]
- [905154502 157559766 259650411]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement