@@ -250,6 +250,7 @@ import qualified Data.Foldable as Foldable
250250import Control.DeepSeq (NFData (rnf ))
251251
252252import Utils.Containers.Internal.StrictPair
253+ import Utils.Containers.Internal.StrictTriple
253254import Utils.Containers.Internal.PtrEquality
254255
255256#if __GLASGOW_HASKELL__
@@ -1318,16 +1319,20 @@ splitS x (Bin _ y l r)
13181319-- | \(O(\log n)\). Performs a 'split' but also returns whether the pivot
13191320-- element was found in the original set.
13201321splitMember :: Ord a => a -> Set a -> (Set a ,Bool ,Set a )
1321- splitMember _ Tip = (Tip , False , Tip )
1322- splitMember x (Bin _ y l r)
1323- = case compare x y of
1324- LT -> let (lt, found, gt) = splitMember x l
1325- ! gt' = link y gt r
1326- in (lt, found, gt')
1327- GT -> let (lt, found, gt) = splitMember x r
1328- ! lt' = link y l lt
1329- in (lt', found, gt)
1330- EQ -> (l, True , r)
1322+ splitMember k0 s = case go k0 s of
1323+ StrictTriple l b r -> (l, b, r)
1324+ where
1325+ go :: Ord a => a -> Set a -> StrictTriple (Set a ) Bool (Set a )
1326+ go _ Tip = StrictTriple Tip False Tip
1327+ go x (Bin _ y l r)
1328+ = case compare x y of
1329+ LT -> let StrictTriple lt found gt = go x l
1330+ ! gt' = link y gt r
1331+ in StrictTriple lt found gt'
1332+ GT -> let StrictTriple lt found gt = go x r
1333+ ! lt' = link y l lt
1334+ in StrictTriple lt' found gt
1335+ EQ -> StrictTriple l True r
13311336#if __GLASGOW_HASKELL__
13321337{-# INLINABLE splitMember #-}
13331338#endif
0 commit comments