diff --git a/src/hitchhiker/tree/core.clj b/src/hitchhiker/tree/core.clj index fa067aa..a9ee782 100644 --- a/src/hitchhiker/tree/core.clj +++ b/src/hitchhiker/tree/core.clj @@ -14,6 +14,7 @@ (defprotocol IResolve "All nodes must implement this protocol. It's includes the minimal functionality necessary to avoid resolving nodes unless strictly necessary." + (index? [_] "Returns true if this is an index node") (last-key [_] "Returns the rightmost key of the node") (dirty? [_] "Returns true if this should be flushed") ;;TODO resolve should be instrumented @@ -103,6 +104,7 @@ (defrecord IndexNode [children storage-addr op-buf cfg] IResolve + (index? [this] true) (dirty? [this] (not (realized? storage-addr))) (resolve [this] this) ;;TODO this is a hack for testing (last-key [this] @@ -213,6 +215,7 @@ (defrecord DataNode [children storage-addr cfg] IResolve + (index? [this] false) (resolve [this] this) ;;TODO this is a hack for testing (dirty? [this] (not (realized? storage-addr))) (last-key [this] diff --git a/test/hitchhiker/tree/core_test.clj b/test/hitchhiker/tree/core_test.clj index acd959c..1798fc8 100644 --- a/test/hitchhiker/tree/core_test.clj +++ b/test/hitchhiker/tree/core_test.clj @@ -21,7 +21,13 @@ data2 (data-node (->Config 3 3 2) (sorted-map 6 6 7 7 8 8 9 9 10 10)) root (->IndexNode [data1 data2] (promise) [] (->Config 3 3 2))] (is (= (map first (lookup-fwd-iter root 4)) (range 4 11))) - (is (= (map first (lookup-fwd-iter root 0)) (range 1 11)))))) + (is (= (map first (lookup-fwd-iter root 0)) (range 1 11))))) + + (testing "index nodes identified as such" + (let [data (data-node (->Config 3 3 2) (sorted-map 1 1)) + root (->IndexNode [data] (promise) [] (->Config 3 3 2))] + (is (index? root)) + (is (not (index? data)))))) (defn insert-helper [t k]