@@ -395,7 +395,7 @@ equal1 eq = go
395
395
396
396
equal2 :: (k -> k' -> Bool ) -> (v -> v' -> Bool )
397
397
-> 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 [] )
399
399
where
400
400
-- If the two trees are the same, then their lists of 'Leaf's and
401
401
-- '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
429
429
430
430
cmp :: (k -> k' -> Ordering ) -> (v -> v' -> Ordering )
431
431
-> 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 [] )
433
433
where
434
434
go (Leaf k1 l1 : tl1) (Leaf k2 l2 : tl2)
435
435
= compare k1 k2 `mappend`
@@ -445,13 +445,13 @@ cmp cmpk cmpv t1 t2 = go (toList' t1 []) (toList' t2 [])
445
445
go [] [] = EQ
446
446
go [] _ = LT
447
447
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"
449
449
450
450
leafCompare (L k v) (L k' v') = cmpk k k' `mappend` cmpv v v'
451
451
452
452
-- Same as 'equal2' but doesn't compare the values.
453
453
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 [] )
455
455
where
456
456
go (Leaf k1 l1 : tl1) (Leaf k2 l2 : tl2)
457
457
| k1 == k2 && leafEq l1 l2
@@ -482,7 +482,7 @@ equalKeys = go
482
482
leafEq (L k1 _) (L k2 _) = k1 == k2
483
483
484
484
instance Hashable2 HashMap where
485
- liftHashWithSalt2 hk hv salt hm = go salt (toList' hm [] )
485
+ liftHashWithSalt2 hk hv salt hm = go salt (leavesAndCollisions hm [] )
486
486
where
487
487
-- go :: Int -> [HashMap k v] -> Int
488
488
go s [] = s
@@ -531,15 +531,15 @@ instance (Hashable k, Hashable v) => Hashable (HashMap k v) where
531
531
arrayHashesSorted :: Int -> A. Array (Leaf k v ) -> [Int ]
532
532
arrayHashesSorted s = List. sort . List. map (hashLeafWithSalt s) . A. toList
533
533
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
541
541
542
- -- Helper function to detect 'Leaf's and 'Collision's.
542
+ -- | Helper function to detect 'Leaf's and 'Collision's.
543
543
isLeafOrCollision :: HashMap k v -> Bool
544
544
isLeafOrCollision (Leaf _ _) = True
545
545
isLeafOrCollision (Collision _ _) = True
0 commit comments