Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject com.dean/interval-tree "0.1.2"
(defproject com.dean/interval-tree "0.1.3-SNAPSHOT"
:description "Modular, Extensible, Foldable Weight-Balanced Tree"
:url "http://github.com/dco-dev/interval-tree"
:license {:name "Eclipse Public License"
Expand Down
20 changes: 20 additions & 0 deletions src/com/dean/interval_tree/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,23 @@
order/*compare* order/normal-compare]
(->IntervalSet (reduce #(tree/node-add %1 (interval/ordered-pair %2)) (node/leaf) coll)
order/*compare* tree/*t-join* nil {}))))

(comment

(def x (ordered-map {:x 1 :y 2})) ;; (find x :x) => [:x 1]
(def y (ordered-set [1 2 3 4]))



(def x (interval-map
{[1 3] :x1
[4 7] :x2
[8 9] :x3
[0 5] :x4}))

(find x 2) ;; => [2 ([[0 5] :x4] [[1 3] :x1])]

(find x [1 4]) ;; => [[1 4] ([[0 5] :x4] [[1 3] :x1] [[4 7] :x2])]


)
4 changes: 2 additions & 2 deletions src/com/dean/interval_tree/tree/interval_map.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[com.dean.interval-tree.tree.root]
[com.dean.interval-tree.tree.order :as order]
[com.dean.interval-tree.tree.tree :as tree])
(:import [clojure.lang RT]
(:import [clojure.lang RT MapEntry]
[com.dean.interval_tree.tree.root INodeCollection
IBalancedCollection
IOrderedCollection
Expand Down Expand Up @@ -111,7 +111,7 @@
(not (empty? (tree/node-find-intervals root k)))))
(entryAt [this k]
(with-interval-map this
(some->> k (tree/node-find-intervals root) (map node/-kv))))
(some->> k (tree/node-find-intervals root) (mapv node/-kv) (MapEntry. k))))
(assoc [this k v]
(with-interval-map this
(IntervalMap. (tree/node-add root (interval/ordered-pair k) v) cmp alloc stitch _meta)))
Expand Down
8 changes: 7 additions & 1 deletion test/com/dean/interval_tree/interval_map_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@
(is (= [:x7 :x3] (x 8.00000001)))
(is (= [:x7 :x3] (x 8.99999999)))
(is (= [:x7 :x3 :x6] (x 9)))
(is (empty? (x 9.00000001))))
(is (empty? (x 9.00000001)))
(testing "keyval lookup (find)"
(is (= [1 [[[0 5] :x4] [[1 3] :x1]]] (find x 1)))
(is (= [2 [[[0 5] :x4] [[1 3] :x1]]] (find x 2)))
(is (= [3 [[[0 5] :x4] [[1 3] :x1] [[3 9] :x7]]] (find x 3)))
(is (= [4 [[[0 5] :x4] [[3 9] :x7] [[4 5] :x8] [[4 7] :x2]]] (find x 4)))
(is (empty? (find x 9.00000001)))))
(testing "interval query"
(is (= [:x4] (x [0 0])))
(is (= [:x4] (x [0 0.5])))
Expand Down