Skip to content

Commit 944db6a

Browse files
authored
Merge pull request #25 from cddr/iresolve-index
Add index? method to IResolve
2 parents 27ebb9b + d97f275 commit 944db6a

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/hitchhiker/tree/core.clj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
(defprotocol IResolve
1515
"All nodes must implement this protocol. It's includes the minimal functionality
1616
necessary to avoid resolving nodes unless strictly necessary."
17+
(index? [_] "Returns true if this is an index node")
1718
(last-key [_] "Returns the rightmost key of the node")
1819
(dirty? [_] "Returns true if this should be flushed")
1920
;;TODO resolve should be instrumented
@@ -103,6 +104,7 @@
103104

104105
(defrecord IndexNode [children storage-addr op-buf cfg]
105106
IResolve
107+
(index? [this] true)
106108
(dirty? [this] (not (realized? storage-addr)))
107109
(resolve [this] this) ;;TODO this is a hack for testing
108110
(last-key [this]
@@ -213,6 +215,7 @@
213215

214216
(defrecord DataNode [children storage-addr cfg]
215217
IResolve
218+
(index? [this] false)
216219
(resolve [this] this) ;;TODO this is a hack for testing
217220
(dirty? [this] (not (realized? storage-addr)))
218221
(last-key [this]

test/hitchhiker/tree/core_test.clj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@
2121
data2 (data-node (->Config 3 3 2) (sorted-map 6 6 7 7 8 8 9 9 10 10))
2222
root (->IndexNode [data1 data2] (promise) [] (->Config 3 3 2))]
2323
(is (= (map first (lookup-fwd-iter root 4)) (range 4 11)))
24-
(is (= (map first (lookup-fwd-iter root 0)) (range 1 11))))))
24+
(is (= (map first (lookup-fwd-iter root 0)) (range 1 11)))))
25+
26+
(testing "index nodes identified as such"
27+
(let [data (data-node (->Config 3 3 2) (sorted-map 1 1))
28+
root (->IndexNode [data] (promise) [] (->Config 3 3 2))]
29+
(is (index? root))
30+
(is (not (index? data))))))
2531

2632
(defn insert-helper
2733
[t k]

0 commit comments

Comments
 (0)