     (throw (ex-info (str "Unsupported data-tree node type: "
                          (pr-str (:data/type node)))
                     {:data/type (:data/type node)}))))
-
-
-(defn- assign-keys
-  "Assigns record keys to the children of this node which they would belong
-  to. Returns a lazy sequence of vectors containing the child index and a
-  sequence of record keys."
-  [split-keys record-keys]
-  (->>
-    [nil 0 split-keys record-keys]
-    (iterate
-      (fn [[_ index splits rks]]
-        (when (seq rks)
-          (if (seq splits)
-            ; Take all records coming before the next split key.
-            (let [[in after] (split-with (partial key/before? (first splits)) rks)]
-              [[index in] (inc index) (next splits) after])
-            ; No more splits, emit one final group with any remaining keys.
-            [[(inc index) rks]]))))
-    (drop 1)
-    (take-while first)
-    (map first)))
 
 
 (defn read-batch

                    {:data/type (:data/type node)}))))


; TODO: read-range
; narrow children by which could contain the range, recurse in order


; TODO: read-slice


;; ## Read Functions

(defn- assign-keys
  "Assigns record keys to the children of this node which they would belong
  to. Returns a lazy sequence of vectors containing the child index and a
  sequence of record keys."
  [split-keys record-keys]
  (->>
    [nil 0 split-keys record-keys]
    (iterate
      (fn [[_ index splits rks]]
        (when (seq rks)
          (if (seq splits)
            ; Take all records coming before the next split key.
            (let [[in after] (split-with (partial key/before? (first splits)) rks)]
              [[index in] (inc index) (next splits) after])
            ; No more splits, emit one final group with any remaining keys.
            [[(inc index) rks]]))))
    (drop 1)
    (take-while first)
    (map first)))


(defn read-all
  "Read a lazy sequence of key/map tuples which contain the requested field data
  for every record in the subtree. This function works on both index nodes and
