Skip to content

Commit 2d537c1

Browse files
authored
Improve name for internal toList' helper (#367)
1 parent d4e31f6 commit 2d537c1

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

Data/HashMap/Internal.hs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ equal1 eq = go
395395

396396
equal2 :: (k -> k' -> Bool) -> (v -> v' -> Bool)
397397
-> HashMap k v -> HashMap k' v' -> Bool
398-
equal2 eqk eqv t1 t2 = go (toList' t1 []) (toList' t2 [])
398+
equal2 eqk eqv t1 t2 = go (leavesAndCollisions t1 []) (leavesAndCollisions t2 [])
399399
where
400400
-- If the two trees are the same, then their lists of 'Leaf's and
401401
-- 'Collision's read from left to right should be the same (modulo the
@@ -429,7 +429,7 @@ instance (Ord k, Ord v) => Ord (HashMap k v) where
429429

430430
cmp :: (k -> k' -> Ordering) -> (v -> v' -> Ordering)
431431
-> HashMap k v -> HashMap k' v' -> Ordering
432-
cmp cmpk cmpv t1 t2 = go (toList' t1 []) (toList' t2 [])
432+
cmp cmpk cmpv t1 t2 = go (leavesAndCollisions t1 []) (leavesAndCollisions t2 [])
433433
where
434434
go (Leaf k1 l1 : tl1) (Leaf k2 l2 : tl2)
435435
= compare k1 k2 `mappend`
@@ -445,13 +445,13 @@ cmp cmpk cmpv t1 t2 = go (toList' t1 []) (toList' t2 [])
445445
go [] [] = EQ
446446
go [] _ = LT
447447
go _ [] = GT
448-
go _ _ = error "cmp: Should never happen, toList' includes non Leaf / Collision"
448+
go _ _ = error "cmp: Should never happen, leavesAndCollisions includes non Leaf / Collision"
449449

450450
leafCompare (L k v) (L k' v') = cmpk k k' `mappend` cmpv v v'
451451

452452
-- Same as 'equal2' but doesn't compare the values.
453453
equalKeys1 :: (k -> k' -> Bool) -> HashMap k v -> HashMap k' v' -> Bool
454-
equalKeys1 eq t1 t2 = go (toList' t1 []) (toList' t2 [])
454+
equalKeys1 eq t1 t2 = go (leavesAndCollisions t1 []) (leavesAndCollisions t2 [])
455455
where
456456
go (Leaf k1 l1 : tl1) (Leaf k2 l2 : tl2)
457457
| k1 == k2 && leafEq l1 l2
@@ -482,7 +482,7 @@ equalKeys = go
482482
leafEq (L k1 _) (L k2 _) = k1 == k2
483483

484484
instance Hashable2 HashMap where
485-
liftHashWithSalt2 hk hv salt hm = go salt (toList' hm [])
485+
liftHashWithSalt2 hk hv salt hm = go salt (leavesAndCollisions hm [])
486486
where
487487
-- go :: Int -> [HashMap k v] -> Int
488488
go s [] = s
@@ -531,15 +531,15 @@ instance (Hashable k, Hashable v) => Hashable (HashMap k v) where
531531
arrayHashesSorted :: Int -> A.Array (Leaf k v) -> [Int]
532532
arrayHashesSorted s = List.sort . List.map (hashLeafWithSalt s) . A.toList
533533

534-
-- Helper to get 'Leaf's and 'Collision's as a list.
535-
toList' :: HashMap k v -> [HashMap k v] -> [HashMap k v]
536-
toList' (BitmapIndexed _ ary) a = A.foldr toList' a ary
537-
toList' (Full ary) a = A.foldr toList' a ary
538-
toList' l@(Leaf _ _) a = l : a
539-
toList' c@(Collision _ _) a = c : a
540-
toList' Empty a = a
534+
-- | Helper to get 'Leaf's and 'Collision's as a list.
535+
leavesAndCollisions :: HashMap k v -> [HashMap k v] -> [HashMap k v]
536+
leavesAndCollisions (BitmapIndexed _ ary) a = A.foldr leavesAndCollisions a ary
537+
leavesAndCollisions (Full ary) a = A.foldr leavesAndCollisions a ary
538+
leavesAndCollisions l@(Leaf _ _) a = l : a
539+
leavesAndCollisions c@(Collision _ _) a = c : a
540+
leavesAndCollisions Empty a = a
541541

542-
-- Helper function to detect 'Leaf's and 'Collision's.
542+
-- | Helper function to detect 'Leaf's and 'Collision's.
543543
isLeafOrCollision :: HashMap k v -> Bool
544544
isLeafOrCollision (Leaf _ _) = True
545545
isLeafOrCollision (Collision _ _) = True

0 commit comments

Comments
 (0)