 
 ;; Set
 
-(deftype PersistentSet)
+(deftype PersistentHashSet [h]
+  ICollection
+  (-conj [coll entry]
+    (instance? PersistentHashSet entry)
+    (let [keys (hamt/keys (.-h entry))
+          len (alength keys)]
+      (loop [i 0
+             h h]
+        (if (< i len)
+          (let [k (aget keys i)]
+            (recur (inc i) (hamt/set k true h)))
+          (PersistentHashSet. h))))
+    
+    :else
+    (let [h (hamt/set entry true h)]
+      (PersistentHashSet. h)))
+  
+  IEquiv
+  (-equiv [coll other]
+    (if (and (instance? PersistentHashSet other)
+             (== (count coll) (count other)))
+      (let [keys (hamt/keys h)
+            len   (length keys)]
+        (loop [i 0]
+          (if (< i len)
+            (let [k (aget keys i)]
+              (if (== true (hamt/get k (.-h other)))
+                (recur (inc i))
+                false))
+            true)))
+      false))
+
+  ISeqable
+  (-seq [coll]
+    (let [len (hamt/count h)]
+      (if (== 0 len)
+        nil
+        (let [keys (hamt/keys h)]
+          (loop [i 0
+                 res nil]
+            (if (< i len)
+              (let [key (aget keys i)]
+                (recur (inc i) (cons k res)))
+              res))))))
+  
+  ICounted
+  (-count [coll] (hamt/count h))
+  
+  ILookup
+  (-lookup [coll k]
+    (and (hamt/has k h) k))
+  (-lookup [coll k not-found]
+    (if (hamt/has k h) k not-found))
+  
+  IFn
+  (-invoke [coll k]
+    (-lookup coll k))
+  
+  IPrintable
+  (-pr-str [coll]
+    (let [keys (hamt/keys h)
+          len (alength keys)]
+      (loop [i 0
+             r "#{"]
+        (if (< i len)
+          (let [s (if (zero? i) "" " ")
+                k    (aget keys i)]
+            (recur
+              (inc i)
+              (str r s (pr-str k))))
+          (str r "}"))))))
 
 ; FIXME - allow non-array colls
 (defn set

             (satisfies? ICounted other)
             (== (count coll) (count other)))
      (let [pairs (hamt/pairs h)
              len   (.-length pairs)]
          (loop [i 0]
            (if (< i len)
              (let [pair (aget pairs i)


(defn hash-set
  [& keys]
  (let [len (count keys)]
    (let [f (fn [h]
              (loop [i 0]
                (if (< i len)
                  (do
                    (hamt/set (nth keys i) true h)
                    (recur (inc i))))))
          h (hamt/mutate f (hamt-make))]
      (PersistentHashSet. h))))

(defn set? [coll]
  (satisfies? ISet coll))
