@@ -223,19 +223,26 @@ instance (Hashable k, Hashable v) => Hashable (HashMap k v) where
223
223
where
224
224
go :: Int -> [HashMap k v ] -> Int
225
225
go s [] = s
226
- go s (Leaf _ l : tl) = s `hashLeafWithSalt` l `go` tl
227
- -- For collisions we hashmix hash value, and then array of values' hashes sorted
228
- go s (Collision h a : tl) = (s `H.hashWithSalt` h) `hashCollisionWithSalt` a `go` tl
229
- go s (_ : tl) = s `go` tl
226
+ go s (Leaf _ l : tl)
227
+ = s `hashLeafWithSalt` l `go` tl
228
+ -- For collisions we hashmix hash value
229
+ -- and then array of values' hashes sorted
230
+ go s (Collision h a : tl)
231
+ = (s `H.hashWithSalt` h) `hashCollisionWithSalt` a `go` tl
232
+ go s (_ : tl) = s `go` tl
230
233
231
234
hashLeafWithSalt :: Int -> Leaf k v -> Int
232
235
hashLeafWithSalt s (L k v) = s `H.hashWithSalt` k `H.hashWithSalt` v
233
236
234
237
hashCollisionWithSalt :: Int -> A. Array (Leaf k v ) -> Int
235
- hashCollisionWithSalt s a = L. foldl' H. hashWithSalt s (L. sort (L. map (H. hash . leafValue) (A. toList a)))
238
+ hashCollisionWithSalt s
239
+ = L. foldl' H. hashWithSalt s . arrayHashesSorted
236
240
237
- leafValue :: Leaf k v -> v
238
- leafValue (L _ v) = v
241
+ arrayHashesSorted :: A. Array (Leaf k v ) -> [Int ]
242
+ arrayHashesSorted = L. sort . L. map leafValueHash . A. toList
243
+
244
+ leafValueHash :: Leaf k v -> Int
245
+ leafValueHash (L _ v) = H. hash v
239
246
240
247
-- Helper to get 'Leaf's and 'Collision's as a list.
241
248
toList' :: HashMap k v -> [HashMap k v ] -> [HashMap k v ]
0 commit comments