Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update to prefer functions in Clojure contrib.
  • Loading branch information
fffej committed Feb 14, 2009
1 parent a184c6b commit 520bfb3
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions huffman.clj
@@ -1,18 +1,7 @@
;;; Huffman encoding
;;; jeff.foster@acm.org
(defn inc-weight
[weight symbol]
(if (contains? weight symbol)
(assoc weight symbol (inc (get weight symbol)))
(assoc weight symbol 1)))

(defn symbol-weights
"Given a list produce a set of symbol weights"
[s]
((fn [p weights]
(if (nil? p)
weights
(recur (rest p) (inc-weight weights (first p))))) s {}))
(ns huffman
(:use clojure.contrib.seq-utils))

(defn- sort-by-second [a b]
(< (second a)(second b)))
Expand Down Expand Up @@ -77,4 +66,5 @@

(defn compress
[s table]
(mapcat (partial get table) s))
(mapcat (partial get table) s))

0 comments on commit 520bfb3

Please sign in to comment.