Skip to content

Instantly share code, notes, and snippets.

@alexott
Created September 24, 2010 11:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexott/595215 to your computer and use it in GitHub Desktop.
Save alexott/595215 to your computer and use it in GitHub Desktop.
(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