Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c99b359

Browse files
Create NonEmptySet type
1 parent 4f29d02 commit c99b359

File tree

5 files changed

+197
-153
lines changed

5 files changed

+197
-153
lines changed

‎containers-tests/tests/set-properties.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,15 @@ mkArb step n
238238
p <- step
239239
q <- step
240240
if dir
241-
then return (Bin 2 q (singleton p) Tip)
242-
else return (Bin 2 p Tip (singleton q))
241+
then return (NE$Bin 2 q (singleton p) Tip)
242+
else return (NE$Bin 2 p Tip (singleton q))
243243
| otherwise = do
244244
-- This assumes a balance factor of delta = 3
245245
let upper = (3*(n - 1)) `quot` 4
246246
let lower = (n + 2) `quot` 4
247247
ln <- liftGen $ choose (lower, upper)
248248
let rn = n - ln - 1
249-
liftM3 (\lt x rt -> Bin n x lt rt) (mkArb step ln) step (mkArb step rn)
249+
liftM3 (\lt x rt -> NE$Bin n x lt rt) (mkArb step ln) step (mkArb step rn)
250250

251251
-- | Given a strictly increasing list of elements, produce an arbitrarily
252252
-- shaped set with exactly those elements.

‎containers/src/Data/Map/Internal.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,7 +1929,7 @@ difference t1 (NE (Bin _ k _ l2 r2)) = case split k t1 of
19291929
withoutKeys :: Ord k => Map k a -> Set k -> Map k a
19301930
withoutKeys Tip _ = Tip
19311931
withoutKeys m Set.Tip = m
1932-
withoutKeys m (Set.Bin _ k ls rs) = case splitMember k m of
1932+
withoutKeys m (Set.NE (Set.Bin _ k ls rs)) = case splitMember k m of
19331933
(lm, b, rm)
19341934
| not b && lm' `ptrEq` lm && rm' `ptrEq` rm -> m
19351935
| otherwise -> link2 lm' rm'
@@ -3356,7 +3356,8 @@ assocs m
33563356

33573357
keysSet :: Map k a -> Set.Set k
33583358
keysSet Tip = Set.Tip
3359-
keysSet (NE (Bin sz kx _ l r)) = Set.Bin sz kx (keysSet l) (keysSet r)
3359+
keysSet (NE (Bin sz kx _ l r)) = Set.NE $
3360+
Set.Bin sz kx (keysSet l) (keysSet r)
33603361

33613362
-- | /O(n)/. Build a map from a set of keys and a function which for each key
33623363
-- computes its value.
@@ -3366,7 +3367,7 @@ keysSet (NE (Bin sz kx _ l r)) = Set.Bin sz kx (keysSet l) (keysSet r)
33663367

33673368
fromSet :: (k -> a) -> Set.Set k -> Map k a
33683369
fromSet _ Set.Tip = Tip
3369-
fromSet f (Set.Bin sz x l r) = NE $ Bin sz x (f x) (fromSet f l) (fromSet f r)
3370+
fromSet f (Set.NE (Set.Bin sz x l r)) = NE $ Bin sz x (f x) (fromSet f l) (fromSet f r)
33703371

33713372
{--------------------------------------------------------------------
33723373
Lists

‎containers/src/Data/Map/Strict/Internal.hs

Lines changed: 2 additions & 1 deletion
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` NE (Bin sz x v (fromSet f l) (fromSet f r))
1472+
fromSet f (Set.NE (Set.Bin sz x l r)) = case f x of
1473+
v -> v `seq` NE (Bin sz x v (fromSet f l) (fromSet f r))
14731474

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

‎containers/src/Data/Set.hs

Lines changed: 1 addition & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /