Skip to content

Instantly share code, notes, and snippets.

@rhz
Created December 5, 2010 07:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhz/728919 to your computer and use it in GitHub Desktop.
Save rhz/728919 to your computer and use it in GitHub Desktop.
diff --git a/src/main/clojure/clojure/data/finger_tree.clj b/src/main/clojure/clojure/data/finger_tree.clj
index bc00343..557aaaf 100644
--- a/src/main/clojure/clojure/data/finger_tree.clj
+++ b/src/main/clojure/clojure/data/finger_tree.clj
@@ -537,13 +537,17 @@
(count [_] (:len (measured tree)))
IPersistentSet
(disjoin [this k]
- (let [[l x r] (split-tree tree #(>= 0 (cmpr k (:right %))))]
- (if (= x k)
- (CountedSortedSet. cmpr (ft-concat l r))
- this)))
+ (if (empty? tree)
+ this
+ (let [[l x r] (split-tree tree #(>= 0 (cmpr k (:right %))))]
+ (if (= x k)
+ (CountedSortedSet. cmpr (ft-concat l r))
+ this))))
(get [_ k]
- (let [x (second (split-tree tree #(>= 0 (cmpr k (:right %)))))]
- (when (= x k) k)))
+ (if (empty? tree)
+ nil
+ (let [x (second (split-tree tree #(>= 0 (cmpr k (:right %)))))]
+ (when (= x k) k))))
Indexed
(nth [this n notfound] (if (< -1 n (:len (measured tree)))
(second (split-tree tree #(> (:len %) n)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment