Skip to content

Instantly share code, notes, and snippets.

@syou6162
Created December 24, 2013 15:58
Show Gist options
  • Save syou6162/8115062 to your computer and use it in GitHub Desktop.
Save syou6162/8115062 to your computer and use it in GitHub Desktop.
;; 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}
@syou6162
Copy link
Author

vectorにすると割と大きなhashcodeが帰ってくるのが気になる。

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