        
         ;; keeping single root
         (== (alength roots) 1)
-          (BTSet. (aget roots 0) (.-shift set) *cmp*)
+          (alter-btset set
+            (aget roots 0)
+            (.-shift set)
+            (inc (.-cnt set)))
        
         ;; introducing new root
         :else
-          (BTSet. (Node. (.map roots lim-key) roots) (+ (.-shift set) level-shift) *cmp*)))))
+          (alter-btset set
+            (Node. (.map roots lim-key) roots)
+            (+ (.-shift set) level-shift)
+            (inc (.-cnt set)))))))
 
 (defn btset-disj [set key]
   (binding [*cmp* (.-comparator set)]


;; perf

(def test-matrix [:target    { "sorted-set" (sorted-set)
                               "btset"      (btset)}
;;                   :distinct? [true false]
                  :size    [100 500 1000 2000 5000 10000 20000 50000]
;;                   :size      [100 500 20000]
                  :method    { "conj"    (fn [opts] (into (:target opts) (:range opts)))
                               "disj"    (fn [opts] (reduce disj (:set opts) (shuffle (:range opts))))
                               "lookup"  (fn [opts] (contains? (:set opts) (rand-int (:size opts))))

  ILookup 
  (-lookup [set k]
    (-lookup set k nil))
  (-lookup [_ k not-found]
    (binding [*cmp* comparator]
      (or (.lookup root k) not-found)))

  ISeqable
  (-seq [this]
    (btset-iter this))
  
  ICounted
  (-count [_] cnt)
 
  IFn
  (-invoke [coll k]
    (-lookup coll k))
  (-invoke [coll k not-found]
    (-lookup coll k not-found))
  
  IPrintWithWriter
  (-pr-writer [this writer opts]
    (pr-sequential-writer writer pr-writer "#{" " " "}" opts (seq this))))

(defn alter-btset [set root shift cnt]
  (BTSet. root shift cnt (.-comparator set) (.-meta set) nil))

(defn btset-by
  ([cmp] (BTSet. (LeafNode. (array)) 0 0 cmp nil 0))
  ([cmp & keys]
    (reduce -conj (btset-by cmp) keys)))

