File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 960960 h1 (m3-mix-H1 m3-seed k1)]
961961 (m3-fmix h1 4 ))))
962962
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+ high (.getInt32 (js/DataView. buf 0 4 ))
970+ low (.getInt32 (js/DataView. buf 4 4 ))]
971+ (hash-long high low)))
972+
963973(defn ^number m3-hash-unencoded-chars [in]
964974 (let [h1 (loop [i 1 h1 m3-seed]
965975 (if (< i (.-length in))
10211031
10221032 (number? o)
10231033 (if ^boolean (js/isFinite o)
1024- (js-mod (Math/floor o) 2147483647 )
1034+ (if-not ^boolean (.isSafeInteger js/Number o)
1035+ (hash-double o)
1036+ (js-mod (Math/floor o) 2147483647 ))
10251037 (case o
10261038 ##Inf
10271039 2146435072
Original file line number Diff line number Diff line change 9393(deftest test-cljs-1818
9494 (is (= (hash true ) 1231 ))
9595 (is (= (hash false ) 1237 )))
96+
97+ (deftest test-cljs-3410
98+ (testing " Small doubles 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 ))))
101+ (testing " Same double hashes the same"
102+ (is (= (hash 0.5 ) (hash 0.5 )))
103+ (is (= (hash -0.32553251 ) (hash -0.32553251 )))
104+ (is (= (hash -0.0000032553251 ) (hash -0.0000032553251 )))))
You can’t perform that action at this time.
0 commit comments