Skip to content

Commit 69151b7

Browse files
committed
Format the code (shorter lines)
1 parent 3c9c284 commit 69151b7

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

Data/HashMap/Base.hs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,19 +223,26 @@ instance (Hashable k, Hashable v) => Hashable (HashMap k v) where
223223
where
224224
go :: Int -> [HashMap k v] -> Int
225225
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
230233

231234
hashLeafWithSalt :: Int -> Leaf k v -> Int
232235
hashLeafWithSalt s (L k v) = s `H.hashWithSalt` k `H.hashWithSalt` v
233236

234237
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
236240

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
239246

240247
-- Helper to get 'Leaf's and 'Collision's as a list.
241248
toList' :: HashMap k v -> [HashMap k v] -> [HashMap k v]

0 commit comments

Comments
 (0)