Skip to content

Commit 66a0549

Browse files
committed
Create NonEmptySet type
1 parent a34deb2 commit 66a0549

File tree

5 files changed

+188
-144
lines changed

5 files changed

+188
-144
lines changed

Diff for: Data/Map/Internal.hs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1923,7 +1923,7 @@ difference t1 (Bin (NonEmptyMap _ k _ l2 r2)) = case split k t1 of
19231923
withoutKeys :: Ord k => Map k a -> Set k -> Map k a
19241924
withoutKeys Tip _ = Tip
19251925
withoutKeys m Set.Tip = m
1926-
withoutKeys m (Set.Bin _ k ls rs) = case splitMember k m of
1926+
withoutKeys m (Set.Bin (Set.NonEmptySet _ k ls rs)) = case splitMember k m of
19271927
(lm, b, rm)
19281928
| not b && lm' `ptrEq` lm && rm' `ptrEq` rm -> m
19291929
| otherwise -> link2 lm' rm'
@@ -3316,7 +3316,8 @@ assocs m
33163316

33173317
keysSet :: Map k a -> Set.Set k
33183318
keysSet Tip = Set.Tip
3319-
keysSet (Bin (NonEmptyMap sz kx _ l r)) = Set.Bin sz kx (keysSet l) (keysSet r)
3319+
keysSet (Bin (NonEmptyMap sz kx _ l r)) = Set.Bin $
3320+
Set.NonEmptySet sz kx (keysSet l) (keysSet r)
33203321

33213322
-- | /O(n)/. Build a map from a set of keys and a function which for each key
33223323
-- computes its value.
@@ -3326,7 +3327,7 @@ keysSet (Bin (NonEmptyMap sz kx _ l r)) = Set.Bin sz kx (keysSet l) (keysSet r)
33263327

33273328
fromSet :: (k -> a) -> Set.Set k -> Map k a
33283329
fromSet _ Set.Tip = Tip
3329-
fromSet f (Set.Bin sz x l r) = Bin $ NonEmptyMap sz x (f x) (fromSet f l) (fromSet f r)
3330+
fromSet f (Set.Bin (Set.NonEmptySet sz x l r)) = Bin $ NonEmptyMap sz x (f x) (fromSet f l) (fromSet f r)
33303331

33313332
{--------------------------------------------------------------------
33323333
Lists

Diff for: Data/Map/Strict/Internal.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1469,7 +1469,8 @@ mapKeysWith c f = fromListWith c . foldrWithKey (\k x xs -> (f k, x) : xs) []
14691469

14701470
fromSet :: (k -> a) -> Set.Set k -> Map k a
14711471
fromSet _ Set.Tip = Tip
1472-
fromSet f (Set.Bin sz x l r) = case f x of v -> v `seq` Bin (NonEmptyMap sz x v (fromSet f l) (fromSet f r))
1472+
fromSet f (Set.Bin (Set.NonEmptySet sz x l r)) = case f x of
1473+
v -> v `seq` Bin (NonEmptyMap sz x v (fromSet f l) (fromSet f r))
14731474

14741475
{--------------------------------------------------------------------
14751476
Lists

Diff for: Data/Set.hs

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ module Data.Set (
7070
Set -- instance Eq,Ord,Show,Read,Data,Typeable
7171
#else
7272
Set(..)
73+
, NonEmptySet(..)
7374
#endif
7475

7576
-- * Construction

0 commit comments

Comments
 (0)