aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Engelberg <mark.engelberg@gmail.com>2010-07-18 21:00:22 -0700
committerMark Engelberg <mark.engelberg@gmail.com>2010-07-18 21:00:22 -0700
commit08b2d37a962cc5baf2c37ad767067233eadfc6ca (patch)
treebb25ce2437b7c3db864e5c28f37f1e7a8db8feb5
parent18c8713709e4cb095d10b154854f8d0b8fb50ad8 (diff)
Fixed hashCode of priority maps in clojure.contrib.priority-map
-rw-r--r--src/main/clojure/clojure/contrib/priority_map.clj17
1 files changed, 5 insertions, 12 deletions
diff --git a/src/main/clojure/clojure/contrib/priority_map.clj b/src/main/clojure/clojure/contrib/priority_map.clj
index 0a1ad51a..6ccf5fd0 100644
--- a/src/main/clojure/clojure/contrib/priority_map.clj
+++ b/src/main/clojure/clojure/contrib/priority_map.clj
@@ -207,18 +207,10 @@ to Clojure's assortment of built-in maps (hash-map and sorted-map).
; cons defines conj behavior
(cons [this e] (let [[item priority] e] (.assoc this item priority)))
- ;This implementation of equiv is a direct translation of the one found in APersistentMap
- (equiv [this o]
- (cond
- (not (instance? Map o)) false
- (not= (count this) (count o)) false
- :else (loop [s (.seq this)]
- (if (nil? s) true
- (let [^java.util.Map$Entry e (first s),
- found (.containsKey ^Map o (.getKey e))]
- (if (or (not found) (not (clojure.lang.Util/equiv (.getValue e) (.get ^Map o (.getKey e)))))
- false
- (recur (next s))))))))
+ ; Like sorted maps, priority maps are equal to other maps provided
+ ; their key-value pairs are the same.
+ (equiv [this o] (= item->priority o))
+ (hashCode [this] (.hashCode item->priority))
;containsKey implements (contains? pm k) behavior
(containsKey [this item] (contains? item->priority item))
@@ -328,6 +320,7 @@ Returns a new priority map with supplied mappings"
h {:a 2 :b 1 :c 3 :d 5 :e 4 :f 3}]
(are [x y] (= x y)
p {:a 2 :b 1 :c 3 :d 5 :e 4 :f 3}
+ (.hashCode p) (.hashCode {:a 2 :b 1 :c 3 :d 5 :e 4 :f 3})
(assoc p :g 1) (assoc h :g 1)
(assoc p :g 0) (assoc h :g 0)
(assoc p :c 4) (assoc h :c 4)