         (let [new-keys (splice keys idx (inc idx) #js [])]
           (rotate (LeafNode. new-keys) root? left right))))))
 
-(defn ^array keys-for [set ^number path]
+(defn keys-for [set path]
   (loop [level (.-shift set)
          node  (.-root set)]
     (if (pos? level)


(declare BTSet Node LeafNode)

(def ^:const ^number min-len 64)
(def ^:const ^number max-len 128)
(def ^:const ^number level-shift (->> (range 31 -1 -1)
                              (filter #(bit-test max-len %))
                              first
                              inc))
(def ^:const ^number path-mask (dec (bit-shift-left 1 level-shift)))
(def ^:const ^number empty-path 0)
(def ^:dynamic *cmp*)

(defn ^number path-get [^number path
                        ^number level]
  (bit-and path-mask
           (unsigned-bit-shift-right path level)))

(defn ^number path-set [^number path
                        ^number level
                        ^number idx]
  (bit-or path 
          (bit-shift-left idx level)))

(defn eq ^boolean [^number a
                   ^number b]
  (== 0 (*cmp* a b)))

(defn ^number half [^number x]
  (fix (/ x 2)))

(defn ^number binary-search [^array arr ^number l ^number r k]
  (if (<= l r)
    (let [m   (half (+ l r))
          mk  (aget arr m)
          cmp ^number (*cmp* mk k)]
      (cond
        (neg? cmp) (recur arr (inc m) r k)
        (pos? cmp) (recur arr l (dec m) k)
        :else m))
    l))
    
(defn ^number lookup-exact [^array arr key]
  (let [arr-l (alength arr)
        idx   (binary-search arr 0 (dec arr-l) key)]
    (if (and (< idx arr-l)

      idx
      -1)))

(defn lookup-range [arr key]
  (let [arr-l (alength arr)
        idx   (binary-search arr 0 (dec arr-l) key)]
    (if (== idx arr-l)
      -1
      idx)))

(defn lookup-insert-leaf [arr key]
  (binary-search arr 0 (- (alength arr) 1) key))

(defn lookup-insert-node [arr key]
  (binary-search arr 0 (- (alength arr) 2) key))

(defn -seek [set key]
  (loop [node  (.-root set)
         path  empty-path
         level (.-shift set)]
