Skip to content
Browse files

fix map hashes for 1.6

  • Loading branch information...
1 parent 21d232a commit d4ea6e98847e987fa2b6a5214ee835d810991c12 @ztellman committed Mar 12, 2014
Showing with 32 additions and 20 deletions.
  1. +1 −1 project.clj
  2. +31 −16 src/potemkin/collections.clj
  3. +0 −3 src/potemkin/template.clj
View
2 project.clj
@@ -3,7 +3,7 @@
:description "Some useful facades."
:dependencies [[clj-tuple "0.1.2"]
[riddley "0.1.6"]]
- :profiles {:dev {:dependencies [[org.clojure/clojure "1.5.1"]
+ :profiles {:dev {:dependencies [[org.clojure/clojure "1.6.0-master-SNAPSHOT"]
[criterium "0.4.1"]
[collection-check "0.1.1-SNAPSHOT"]]}
:1.6 {:dependencies [[org.clojure/clojure "1.6.0-master-SNAPSHOT"]]}}
View
47 src/potemkin/collections.clj
@@ -18,24 +18,29 @@
(RuntimeException.
~(str "Wrong number of args (" actual ")"))))
+(defmacro compile-if [test then else]
+ (if (eval test)
+ then
+ else))
+
(eval
(unify-gensyms
`(def-abstract-type PotemkinFn
java.util.concurrent.Callable
(call [this##]
(.invoke ~(with-meta `this## {:tag "clojure.lang.IFn"})))
-
+
java.lang.Runnable
(run [this##]
(.invoke ~(with-meta `this## {:tag "clojure.lang.IFn"})))
-
+
clojure.lang.IFn
~@(map
(fn [n]
`(~'invoke [this# ~@(repeat n '_)]
~(throw-arity n)))
(range 0 21))
-
+
(applyTo [this## args##]
(let [cnt# (count args##)]
(case cnt#
@@ -49,7 +54,7 @@
(def-abstract-type AbstractMap
potemkin.collections.PotemkinMap
-
+
clojure.lang.MapEquivalence
clojure.lang.IPersistentCollection
@@ -89,11 +94,21 @@
[this f val#]
(reduce f val# (seq this)))
+ clojure.lang.IHashEq
+ (hasheq [this]
+ (potemkin.collections/compile-if (resolve 'clojure.core/hash-unordered-coll)
+ (hash-unordered-coll (or (seq this) ()))
+ (reduce
+ (fn [acc [k v]]
+ (unchecked-add acc (bit-xor (hash k) (hash v))))
+ 0
+ (seq this))))
+
Object
(hashCode [this]
(reduce
(fn [acc [k v]]
- (unchecked-add acc (bit-xor (hash k) (hash v))))
+ (unchecked-add acc (bit-xor (.hashCode k) (.hashCode v))))
0
(seq this)))
@@ -120,7 +135,7 @@
(let [v (.valAt this k ::not-found)]
(when (not= v ::not-found)
(clojure.lang.MapEntry. k v))))
-
+
(assoc [this k v]
(potemkin.collections/assoc* this k v))
@@ -129,7 +144,7 @@
(empty [this]
(potemkin.collections/empty* this))
-
+
java.util.Map
(get [this k]
(.valAt this k))
@@ -235,22 +250,22 @@
(let [key-set (->> key-vals (partition 2) (map first) set)]
(unify-gensyms
`(do
-
+
(def-map-type ~name ~(vec (conj params `added## `removed##))
-
+
(~'get [this# key# default-value#]
(cond
(contains? added## key#)
(get added## key#)
-
+
(contains? removed## key#)
default-value#
-
+
:else
(case key#
~@key-vals
default-value#)))
-
+
(~'keys [this#]
(let [keys# ~key-set
keys# (if-not (empty? removed##)
@@ -260,18 +275,18 @@
(set (concat keys# (keys added##)))
keys#)]
keys#))
-
+
(~'assoc [this# key# value#]
(new ~name ~@params (assoc added## key# value#) removed##))
-
+
(~'dissoc [this# key#]
(cond
(contains? added## key#)
(new ~name ~@params (dissoc added## key#) removed##)
-
+
(contains? ~key-set key#)
(new ~name ~@params added## (set (conj removed## key#)))
-
+
:else
this#)))
View
3 src/potemkin/template.clj
@@ -90,6 +90,3 @@
:else
(list 'quote x))))
body)))))
-
-(deftemplate plus-one [y] [x z]
- (+ y x ~(inc z)))

0 comments on commit d4ea6e9

Please sign in to comment.
Something went wrong with that request. Please try again.