Advertisement
Guest User

Untitled

a guest
Mar 15th, 2013
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. user=> (= (byte-array (map byte [1 2 3])) (byte-array (map byte [1 2 3]))) ; not equal
  2. false
  3. 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
  4. IllegalArgumentException Duplicate key: (byte-array (map byte [1 2 3]))  clojure.lang.PersistentArrayMap.createWithCheck (PersistentArrayMap.java:70)
  5. user=> (def a (byte-array (map byte [1 2 3]))
  6. )
  7. #'user/a
  8. user=> (def b (byte-array (map byte [1 2 3])))
  9. #'user/b
  10. user=> (= a b) ; again, not equal
  11. false
  12. user=> (.hashCode a) ; ...different hashes!
  13. 2137552888
  14. user=> (.hashCode b)
  15. 545732387
  16. user=> {a 1, b 2} ; no complaints from the hash-map constructor
  17. {#<byte[] [B@7f6877f8> 1, #<byte[] [B@20873723> 2}
  18.  
  19. ; I thought maybe the reader was caching the two arrays created in the same expression, but I can't replicate that:
  20. user=> (map #(.hashCode %) [(byte-array (map byte [1 2 3])) (byte-array (map byte [1 2 3])) (byte-array (map byte [2 3 4]))])
  21. (1629818866 1211763377 1519652738)
  22. 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])))]
  23. [905154502 157559766 259650411]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement