 (ns algorithms-clj.huffman
   (:require
-    [clojure.data.priority-map :as prio :refer [priority-map]]
+    [clojure.data.priority-map :as prio]
+    [clojure.set :as set] 
     ))
 
 

(defn- make-node
  "Build an intermediary node from two sub-trees"
  [[c1 w1] [c2 w2]]
  (let [vals (into (:values c1) (:values c2))]
    [{:values vals :lhs c1 :rhs c2} (+ w1 w2)]
    ))

(defn- merge-lowest
  "Merge the two lowest priority elements"
  [heap]
  (let [rest (pop heap)]
    (conj (pop rest)
      (make-node (peek heap) (peek rest))
      )))

(defn- merge-lowest-recursively
  "Build the huffman tree from the priority map"

  [value-frequency-pairs]
  (->>
    value-frequency-pairs
    (into (prio/priority-map) (map make-leaf))
    merge-lowest-recursively
    first ;; First element of the leaf
    ))


;; -----------------------------------------------------------
