Skip to content

Commit

Permalink
something strange is happening. check out the insert-test output. it's
Browse files Browse the repository at this point in the history
putting the first 5 items at the same offset, and then the rest are
at seemingly random huge numbers, with no apparent trend. only a
single item is being found
  • Loading branch information
Rosnec committed May 1, 2014
1 parent 414f645 commit 2831256
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
9 changes: 7 additions & 2 deletions src/b_plus_tree/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,19 @@
; record doesn't exist already, so we can insert
(let [free
(if-not (b-plus-tree.nodes/full? leaf order)
(insert-record key val leaf free page-size raf)
(insert-record key val
(assoc leaf
:free free)
free page-size raf)
; placeholder
free)
new-root (assoc (if (= :root-leaf (:type leaf))
leaf
root)
:free free)]
(b-plus-tree.io/write-node new-root raf))))))
(when-not (= :root-leaf (:type leaf))
(b-plus-tree.io/write-node (assoc root
:free free))))))))

(defn traverse
"Returns a lazy sequence of the key value pairs contained in the B+ Tree,
Expand Down
8 changes: 4 additions & 4 deletions src/b_plus_tree/nodes.clj
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ fields."
"Returns a new leaf root."
([page-size]
{:type :root-leaf,
:next-free page-size,
:keys [],
:children [],
:offset 0}))
:page-size page-size
:free page-size,
:key-ptrs (sorted-map)
:offset 0}))

(def leaf-types
#{:root-leaf :leaf})
Expand Down
5 changes: 3 additions & 2 deletions test/b_plus_tree/insert_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@

(deftest insert-simple-test
(testing "simple insertion"
(io/delete-file "/tmp/RAF" true)
(with-open [raf (new java.io.RandomAccessFile "/tmp/RAF" "rwd")]
(doall (map (fn [[k v]]
(println "inserting" k)
(b-plus-tree.core/insert k v (-> key-vals count (- 2))
(b-plus-tree.core/insert k v (-> key-vals count)
100 raf))
key-vals))
(doall (map (fn [[k v]]
(println "finding" k)
(is (= v (b-plus-tree.core/find k 100 raf))))
key-vals)))
(io/delete-file "/tmp/RAF")))
(io/delete-file "/tmp/RAF" true)))

0 comments on commit 2831256

Please sign in to comment.