X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Data%2FSet.hs;h=4b1e3a93ab406746f000f721c2b2c1ca1d788bbf;hb=28fb12f4e4059674e9396fc76a2783e0ae8798cd;hp=fb58ce202818e0b9f002c48bbbcce1c4b6efe065;hpb=42459d4ce473c881242c8c24c0cd570c3288393e;p=ghc-base.git diff --git a/Data/Set.hs b/Data/Set.hs index fb58ce2..4b1e3a9 100644 --- a/Data/Set.hs +++ b/Data/Set.hs @@ -250,7 +250,7 @@ isSubsetOfX t Tip = False isSubsetOfX (Bin _ x l r) t = found && isSubsetOfX l lt && isSubsetOfX r gt where - (found,lt,gt) = splitMember x t + (lt,found,gt) = splitMember x t {-------------------------------------------------------------------- @@ -347,7 +347,7 @@ intersect' t (Bin _ x l r) | found = join x tl tr | otherwise = merge tl tr where - (found,lt,gt) = splitMember x t + (lt,found,gt) = splitMember x t tl = intersect' lt l tr = intersect' gt r @@ -427,7 +427,7 @@ elems s {-------------------------------------------------------------------- Lists --------------------------------------------------------------------} --- | /O(n)/. Convert the set to an ascending list of elements. +-- | /O(n)/. Convert the set to a list of elements. toList :: Set a -> [a] toList s = toAscList s @@ -616,13 +616,13 @@ split x (Bin sy y l r) -- | /O(log n)/. Performs a 'split' but also returns whether the pivot -- element was found in the original set. -splitMember :: Ord a => a -> Set a -> (Bool,Set a,Set a) -splitMember x Tip = (False,Tip,Tip) +splitMember :: Ord a => a -> Set a -> (Set a,Bool,Set a) +splitMember x Tip = (Tip,False,Tip) splitMember x (Bin sy y l r) = case compare x y of - LT -> let (found,lt,gt) = splitMember x l in (found,lt,join y gt r) - GT -> let (found,lt,gt) = splitMember x r in (found,join y l lt,gt) - EQ -> (True,l,r) + LT -> let (lt,found,gt) = splitMember x l in (lt,found,join y gt r) + GT -> let (lt,found,gt) = splitMember x r in (join y l lt,found,gt) + EQ -> (l,True,r) {-------------------------------------------------------------------- Utility functions that maintain the balance properties of the tree.