Created
September 24, 2010 11:31
-
-
Save alexott/595215 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
(defn calc-occuriences-trans [^String text] | |
(let [res (reduce (fn [m ^Character c] | |
(let [ch (Character/toUpperCase c)] | |
(assoc! m ch (+ 1 (m ch 0))))) (transient {}) text)] | |
(persistent! res))) | |
;; (calc-occuriences-trans (slurp "/home/ott/tmp/1/dict" :encoding "ISO-8859-1")) => 1.5-2 sec | |
(defn calc-occuriences [^String text] | |
(let [tmap (map (fn [^Character ch] (hash-map (Character/toUpperCase ch) 1)) text)] | |
(apply merge-with + tmap))) | |
;; (calc-occuriences (slurp "/home/ott/tmp/1/dict" :encoding "ISO-8859-1")) => 6-7 sec | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment