   (instance? DataNode node))
 
 ;(println (b-tree :foo :bar :baz))
-;(pp/pprint (b-tree :foo :bar :baz))
+;(pp/pprint (apply b-tree (range 100)))
 (defn print-data-node
   [node ^Writer writer fully-qualified?]
   (.write writer (if fully-qualified?

           cleaned-node (assoc tree :children cleaned-children)
           new-addr (->TestingAddr (last-key tree) cleaned-node)]
       (deliver (:storage-addr tree) new-addr)
       {:tree new-addr :stats (update-in stats [:writes] inc)})
     {:tree tree :stats stats})))

(comment
  (clojure.pprint/pprint (apply b-tree (range 30)))

  (let [t (:tree (flush-tree (apply b-tree (range 30))))]
    (assert (= 0 (:writes (:stats (flush-tree t)))))
    (assert (= (range 30) (lookup-fwd-iter t -1)))
    (:stats (flush-tree (insert t -7)))
    )



  (last-key [_] last-key)
  (resolve [_] node))

(defn print-testing-addr
  [node ^Writer writer fully-qualified?]
  (.write writer (if fully-qualified?
                   (pr-str TestingAddr)
                   "TestingAddr"))
  (.write writer (str {})))

(defmethod print-method TestingAddr
  [node writer]
  (print-testing-addr node writer false))

(defmethod print-dup TestingAddr
  [node writer]
  (print-testing-addr node writer true))

(defmethod pp/simple-dispatch TestingAddr
  [node]
  (let [out ^Writer *out*]
    (.write out (str "TestingAddr"
                     (node-status-bits node)))
    (.write out (str {}))))

;;TODO make this a loop/recur instead of mutual recursion
(declare flush-tree)

