File tree 2 files changed +18
-1
lines changed
2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change 960
960
h1 (m3-mix-H1 m3-seed k1)]
961
961
(m3-fmix h1 4 ))))
962
962
963
+ (defn hash-long [high low]
964
+ (bit-xor high low))
965
+
966
+ (defn hash-double [f]
967
+ (let [arr (doto (js/Float64Array. 1 ) (aset 0 f))
968
+ buf (.-buffer arr)
969
+ low (.getInt32 (js/DataView. buf 0 4 ))
970
+ high (.getInt32 (js/DataView. buf 4 4 ))]
971
+ (hash-long high low)))
972
+
963
973
(defn ^number m3-hash-unencoded-chars [in]
964
974
(let [h1 (loop [i 1 h1 m3-seed]
965
975
(if (< i (.-length in))
1021
1031
1022
1032
(number? o)
1023
1033
(if ^boolean (js/isFinite o)
1024
- (js-mod (Math/floor o) 2147483647 )
1034
+ (if-not (.isInteger js/Number o)
1035
+ (hash-double o)
1036
+ (js-mod (Math/floor o) 2147483647 ))
1025
1037
(case o
1026
1038
##Inf
1027
1039
2146435072
Original file line number Diff line number Diff line change 93
93
(deftest test-cljs-1818
94
94
(is (= (hash true ) 1231 ))
95
95
(is (= (hash false ) 1237 )))
96
+
97
+ (deftest test-cljs-3410
98
+ (testing " Small floats should not hash the same"
99
+ (is (not= (hash-double -0.32553251 ) (hash-double -0.0000032553251 )))
100
+ (is (not= (hash -0.32553251 ) (hash -0.0000032553251 )))))
You can’t perform that action at this time.
0 commit comments