 
 (deftype Node [parent parent-ix keys vals children ^:mutable lower ^:mutable upper]
   Object
-  (update [this key delta max-keys]
-          (let [ix (key-find-gte keys key)]
+  (add [this key max-keys]
+       (let [ix (key-find-gte keys key)]
             (if (and (< ix (alength keys)) (key= key (aget keys ix)))
-              (let [old-val (aget vals ix)
-                    new-val (+ old-val delta)]
-                (if (== 0 new-val)
-                  ;; del
-                  (if (nil? children)
+              false
+              (if (nil? children)
+                (do
+                  (.push! this ix #js [key nil])
+                  (.maintain! this max-keys)
+                  true)
+                (.add (aget children ix) key max-keys)))))
+  (del [this key max-keys]
+       (let [ix (key-find-gte keys key)]
+            (if (and (< ix (alength keys)) (key= key (aget keys ix)))
+              (if (nil? children)
+                (do
+                  (.pop! this ix)
+                  (.maintain! this max-keys)
+                  true)
+                (loop [node (aget children (+ ix 1))]
+                  (if (not (nil? (.-children node)))
+                    (recur (aget (.-children node) 0))
                     (do
-                      (.pop! this ix)
+                      (aset keys ix (aget (.-keys node) 0))
+                      (aset vals ix (aget (.-vals node) 0))
+                      (.pop! node 0)
+                      (.maintain! node max-keys)
                       (.maintain! this max-keys)
-                      deled)
-                    (loop [node (aget children (+ ix 1))]
-                      (if (not (nil? (.-children node)))
-                        (recur (aget (.-children node) 0))
-                        (do
-                          (aset keys ix (aget (.-keys node) 0))
-                          (aset vals ix (aget (.-vals node) 0))
-                          (.pop! node 0)
-                          (.maintain! node max-keys)
-                          (.maintain! this max-keys)
-                          deled))))
-                  ;; change
-                  (do
-                    (aset vals ix new-val)
-                    changed)))
+                      true))))
               (if (nil? children)
-                ;; add
-                (do
-                  (.push! this ix #js [key delta])
-                  (.maintain! this max-keys)
-                  added)
-                ;; recur
-                (.update (aget children ix) key delta max-keys)))))
+                false
+                (.del (aget children ix) key max-keys)))))
   (push! [this ix key&val&child which-child] ;; on leaves, child and which-child are not required
          (.splice keys ix 0 (aget key&val&child 0))
          (.splice vals ix 0 (aget key&val&child 1))


;; TREES

;; update adds the delta to the current value for the key and returns either:
;;   added if the value went from zero to non-zero
;;   changed if the value went from non-zero to non-zero
;;   deled if the value went from non-zero to zero

(def added 1)
(def changed 0)
(def deled -1)

(def left-child 0)
(def right-child 1)


         (set! root (Node. nil nil #js [] #js [] nil nil nil)))
  (toString [this]
            (pr-str (into (sorted-map-by key-compare) (map vec this))))
  (add [this key]
       (.add root key max-keys))
  (del [this key]
       (.del root key max-keys))
  (push! [this ix key&val&child which-child]
           (let [left-child (if (== which-child left-child) (aget key&val&child 2) root)
                 right-child (if (== which-child right-child) (aget key&val&child 2) root)]
