 (ns derive.nativestore
   (:require [goog.object :as obj]
             [purnam.native]
-            [purnam.native.functions :refer [js-lookup js-assoc js-dissoc js-merge js-map]]
+            [purnam.native.functions :refer [js-lookup js-assoc js-dissoc js-merge js-map
+                                             js-copy]]
             [derive.protocols :as p :refer [index! unindex! key-fn comparator-fn scan
                                             insert! delete! add-index! rem-index! get-index]]))
              

  (-lookup [idx val]
    (-lookup idx val nil))
  (-lookup [idx val not-found]
    (let [compfn (.-compfn idx)
          keyfn (.-keyfn idx)
          arry (.-arry idx)
          index (goog.array.binarySearch arry val #(compfn %1 (keyfn %2)))]
      (if (>= index 0)
        (loop [end index]
          (if (= (compfn val (keyfn (aget arry end))) 0)

    (-lookup idx k not-found))

  ICounted
  (-count [idx] (alength (js-keys hashmap)))

  p/IIndex
  (key-fn [idx] keyfn)
  (index! [idx obj]
    (let [key (keyfn obj)
          old (js-lookup hashmap key)]
      (js-assoc hashmap key (if old (upsert-merge old obj) obj))))
  (unindex! [idx obj]
    (let [key (keyfn obj)]
      (js-dissoc hashmap key obj))))

(defn root-index [keyfn]
