@@ -256,6 +256,7 @@ import Data.List.NonEmpty (NonEmpty(..))
256256#endif
257257
258258import Utils.Containers.Internal.StrictPair
259+ import Utils.Containers.Internal.StrictTriple
259260import Utils.Containers.Internal.PtrEquality
260261import Utils.Containers.Internal.EqOrdUtil (EqM (.. ), OrdM (.. ))
261262
@@ -1433,16 +1434,20 @@ splitS x (Bin _ y l r)
14331434-- | \(O(\log n)\). Performs a 'split' but also returns whether the pivot
14341435-- element was found in the original set.
14351436splitMember :: Ord a => a -> Set a -> (Set a ,Bool ,Set a )
1436- splitMember _ Tip = (Tip , False , Tip )
1437- splitMember x (Bin _ y l r)
1438- = case compare x y of
1439- LT -> let (lt, found, gt) = splitMember x l
1440- ! gt' = link y gt r
1441- in (lt, found, gt')
1442- GT -> let (lt, found, gt) = splitMember x r
1443- ! lt' = link y l lt
1444- in (lt', found, gt)
1445- EQ -> (l, True , r)
1437+ splitMember k0 s = case go k0 s of
1438+ StrictTriple l b r -> (l, b, r)
1439+ where
1440+ go :: Ord a => a -> Set a -> StrictTriple (Set a ) Bool (Set a )
1441+ go _ Tip = StrictTriple Tip False Tip
1442+ go x (Bin _ y l r)
1443+ = case compare x y of
1444+ LT -> let StrictTriple lt found gt = go x l
1445+ ! gt' = link y gt r
1446+ in StrictTriple lt found gt'
1447+ GT -> let StrictTriple lt found gt = go x r
1448+ ! lt' = link y l lt
1449+ in StrictTriple lt' found gt
1450+ EQ -> StrictTriple l True r
14461451#if __GLASGOW_HASKELL__
14471452{-# INLINABLE splitMember #-}
14481453#endif
0 commit comments