Created
November 4, 2010 20:07
-
-
Save pepijndevos/663096 to your computer and use it in GitHub Desktop.
This file contains 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 freqs [^bytes blocks] | |
(loop [idx 0 | |
ret (cycle (repeatedly 128 #(transient {})))] | |
(if (< idx (alength blocks)) | |
(do | |
(update! (first ret) (aget blocks idx) (fnil inc 0)) | |
(recur (inc idx) (next ret))) | |
(map persistent! (take 128 ret))))) | |
(defn freqs [^bytes blocks] | |
(map persistent! (persistent! | |
(areduce blocks idx ret (transient (vec (repeatedly 128 #(transient {})))) | |
(let [layer (rem idx 128)] | |
(update-in! ret [layer (aget blocks idx)] (fnil inc 0))))))) | |
(defn freqs [blocks] | |
(->> blocks | |
(partition 128) | |
(reduce (fn [counts col] | |
(doall (map #(assoc! %1 %2 (inc (get %1 %2 0))) counts col))) | |
(repeatedly 128 #(transient {}))) | |
(map persistent!))) | |
(defn freqs [blocks] | |
(->> blocks | |
(partition 128) | |
(apply map vector) | |
(pmap frequencies))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment