Created
December 24, 2013 15:58
-
-
Save syou6162/8115062 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
;; Clojureでのhashcodeの例 | |
(hash "hoge") ; 3208229 | |
;; clojureのvectorはよい | |
(hash [1 2 3]) ; 30817 | |
;; javaの配列は毎回hashcodeが変わってしまうので注意 | |
(hash (int-array [1 2 3])) ; 1628598432 | |
(hash (int-array [1 2 3])) ; 1172445666 | |
;; feature hashingの例 | |
(def *max-hash-length* 10) | |
(rem 3 10) ; 3 | |
(rem 13 10) ; 3 | |
(defn my-frequencies [docs] | |
(->> docs | |
(map hash) | |
(map (fn [x] (rem x *max-hash-length*))) | |
(frequencies))) | |
(my-frequencies ["a" "b" "c"]) ; {7 1, 8 1, 9 1} | |
(my-frequencies ["a" "b" "d"]) ; {7 1, 8 1, 0 1} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
vectorにすると割と大きなhashcodeが帰ってくるのが気になる。