Skip to content

Instantly share code, notes, and snippets.

@pepijndevos
Created November 4, 2010 20:07
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 pepijndevos/663096 to your computer and use it in GitHub Desktop.
Save pepijndevos/663096 to your computer and use it in GitHub Desktop.
(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