Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Eq IntSet and Eq (IntMap a) #1028

Merged
merged 2 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions containers-tests/benchmarks/IntMap.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ main = do
, bench "spanAntitone" $ whnf (M.spanAntitone (<key_mid)) m
, bench "split" $ whnf (M.split key_mid) m
, bench "splitLookup" $ whnf (M.splitLookup key_mid) m
, bench "eq" $ whnf (\m' -> m' == m') m -- worst case, compares everything
]
where
elems = elems_hits
Expand Down
1 change: 1 addition & 0 deletions containers-tests/benchmarks/IntSet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ main = do
, bench "split:sparse" $ whnf (IS.split elem_sparse_mid) s_sparse
, bench "splitMember:dense" $ whnf (IS.splitMember elem_mid) s
, bench "splitMember:sparse" $ whnf (IS.splitMember elem_sparse_mid) s_sparse
, bench "eq" $ whnf (\s' -> s' == s') s -- worst case, compares everything
]
where
bound = 2^12
Expand Down
12 changes: 2 additions & 10 deletions containers/src/Data/IntMap/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3415,8 +3415,7 @@ data Distinct = Distinct | Nondistinct
Eq
--------------------------------------------------------------------}
instance Eq a => Eq (IntMap a) where
t1 == t2 = equal t1 t2
t1 /= t2 = nequal t1 t2
(==) = equal

equal :: Eq a => IntMap a -> IntMap a -> Bool
equal (Bin p1 l1 r1) (Bin p2 l2 r2)
Expand All @@ -3425,14 +3424,7 @@ equal (Tip kx x) (Tip ky y)
= (kx == ky) && (x==y)
equal Nil Nil = True
equal _ _ = False

nequal :: Eq a => IntMap a -> IntMap a -> Bool
nequal (Bin p1 l1 r1) (Bin p2 l2 r2)
= (p1 /= p2) || (nequal l1 l2) || (nequal r1 r2)
nequal (Tip kx x) (Tip ky y)
= (kx /= ky) || (x/=y)
nequal Nil Nil = False
nequal _ _ = True
{-# INLINABLE equal #-}

-- | @since 0.5.9
instance Eq1 IntMap where
Expand Down
11 changes: 1 addition & 10 deletions containers/src/Data/IntSet/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1388,8 +1388,7 @@ data Inserted = Inserted !IntSet ![Key]
Eq
--------------------------------------------------------------------}
instance Eq IntSet where
t1 == t2 = equal t1 t2
t1 /= t2 = nequal t1 t2
(==) = equal

equal :: IntSet -> IntSet -> Bool
equal (Bin p1 l1 r1) (Bin p2 l2 r2)
Expand All @@ -1399,14 +1398,6 @@ equal (Tip kx1 bm1) (Tip kx2 bm2)
equal Nil Nil = True
equal _ _ = False

nequal :: IntSet -> IntSet -> Bool
nequal (Bin p1 l1 r1) (Bin p2 l2 r2)
= (p1 /= p2) || (nequal l1 l2) || (nequal r1 r2)
nequal (Tip kx1 bm1) (Tip kx2 bm2)
= kx1 /= kx2 || bm1 /= bm2
nequal Nil Nil = False
nequal _ _ = True

{--------------------------------------------------------------------
Ord
--------------------------------------------------------------------}
Expand Down