summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Solano Gómez <clojure@sattvik.com>2010-04-21 13:43:47 -0500
committerStuart Halloway <stu@thinkrelevance.com>2010-04-27 15:35:10 -0400
commita3d1d494e9e574599c50dd83749183c66f653192 (patch)
treec250e40af2e5e8577a3e909a1070487940282ce6 /src
parent5ad8870076bf991dd6f81e596be424d5d965956b (diff)
Add Comparable support to Vec, with tests. Fixes #266.
Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
Diffstat (limited to 'src')
-rw-r--r--src/clj/clojure/gvec.clj17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/clj/clojure/gvec.clj b/src/clj/clojure/gvec.clj
index f9e65ba5..ce4fb7d7 100644
--- a/src/clj/clojure/gvec.clj
+++ b/src/clj/clojure/gvec.clj
@@ -335,6 +335,23 @@
(aset arr subidx (.doAssoc this (- level (int 5)) (aget arr subidx) i val))
(VecNode. (.edit node) arr))))
+ java.lang.Comparable
+ (compareTo [this o]
+ (if (identical? this o)
+ 0
+ (let [ocnt (.count (cast clojure.lang.IPersistentVector o))]
+ (cond
+ (< cnt ocnt) -1
+ (> cnt ocnt) 1
+ :else
+ (loop [i (int 0)]
+ (if (= i cnt)
+ 0
+ (let [comp (clojure.lang.Util/compare (.nth this i) (.nth o i))]
+ (if (= 0 comp)
+ (recur (inc i))
+ comp))))))))
+
java.lang.Iterable
(iterator [this]
(let [i (java.util.concurrent.atomic.AtomicInteger. 0)]