File tree Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -220,15 +220,20 @@ equal t1 t2 = go (toList' t1 []) (toList' t2 [])
220
220
go _ _ = False
221
221
222
222
instance (Hashable k , Ord k , Hashable v ) => Hashable (HashMap k v ) where
223
- hashWithSalt salt = L. foldl' ( \ h ( L k v) -> h `H.hashWithSalt` k `H.hashWithSalt` v) salt . toList''
223
+ hashWithSalt salt hm = go salt (toList' hm [] )
224
224
where
225
- -- Order 'Leaf' s with (hash, k) ordering
226
- toList'' :: HashMap k v -> [Leaf k v ]
227
- toList'' hm = concatMap f (toList' hm [] )
228
- f :: HashMap k v -> [Leaf k v ]
229
- f (Leaf _ l) = [l]
230
- f (Collision _ a) = L. sortBy (comparing leafKey) (A. toList a)
231
- f _ = []
225
+ go :: Int -> [HashMap k v ] -> Int
226
+ go salt [] = salt
227
+ go salt (Leaf _ l : tl) = salt `hashLeafWithSalt` l `go` tl
228
+ go salt (Collision _ a : tl) = salt `hashCollisionWithSalt` a `go` tl
229
+ go salt (_ : tl) = salt `go` tl
230
+
231
+ hashLeafWithSalt :: Int -> Leaf k v -> Int
232
+ hashLeafWithSalt s (L k v) = s `H.hashWithSalt` k `H.hashWithSalt` v
233
+
234
+ hashCollisionWithSalt :: Int -> A. Array (Leaf k v ) -> Int
235
+ hashCollisionWithSalt s a = L. foldl' (hashLeafWithSalt) s (L. sortBy (comparing leafKey) (A. toList a))
236
+
232
237
leafKey :: Leaf k v -> k
233
238
leafKey (L k _) = k
234
239
You can’t perform that action at this time.
0 commit comments