Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: NonEmptySet and NonEmptyMap #616

Open
wants to merge 53 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
4f29d02
Create NonEmptyMap type
Ericson2314 Mar 9, 2019
c99b359
Create NonEmptySet type
Ericson2314 Apr 19, 2019
54bfc62
WIP: NonEmptySet functions
Ericson2314 Apr 19, 2019
fe9f75e
Don't close over any previously-unclosed-over variables in helpers
Ericson2314 Apr 21, 2019
0b095ee
Add missing export and type sig
Ericson2314 Apr 22, 2019
3b9e85d
Get rid of `maybe*` helpers
Ericson2314 Apr 22, 2019
1e85fd5
Fix copy paste errors in previous commit
Ericson2314 Apr 22, 2019
df951dd
Break up balance{L,R}
Ericson2314 Apr 22, 2019
5744ff1
Split out Set.insertNE
Ericson2314 Apr 22, 2019
011116f
Avoid pointless `(<$>)`
Ericson2314 Apr 22, 2019
88d0737
Make non-empty versions of a few small Set functions
Ericson2314 Apr 23, 2019
4d3b1cd
Split out Set.deleteNE
Ericson2314 Apr 22, 2019
a27f0cc
non-empty versions of `isSubsetOf`, `isProperSubsetOf`, and `disjoint`
Ericson2314 Apr 23, 2019
27c4227
Add `nonEmpty :: Set a => Maybe (NonEmptySet a)`
Ericson2314 May 4, 2019
384d7cb
Covert a bunch more functions
Ericson2314 May 4, 2019
73f5660
Rename `Set.Bin` to `Set.Bin'`, and expose `Bin` pattern synnonym
Ericson2314 May 4, 2019
833925c
Convert more functions
Ericson2314 May 4, 2019
eb7e2fb
More CPP for pattern synonym signature
Ericson2314 May 4, 2019
bb79677
Non-Empty showTree debugging aids
Ericson2314 May 4, 2019
4ac7467
Create and expose non-empty link and merge
Ericson2314 May 4, 2019
6e7dee3
Add complete pragma
alexfmpe Jun 11, 2019
41304d6
Rename `Map.Bin` to `Map.Bin'`, and expose `Bin` pattern synonym
alexfmpe Jun 11, 2019
20e5c84
Merge remote-tracking branch 'upstream/master' into non-empty
Ericson2314 Jun 22, 2019
0cc2487
Repair benchmarks to account for `Bin` renaming
fosskers Jun 23, 2019
0f09e90
Map: NE variants up to `lookup*`
fosskers Jun 24, 2019
aa70684
Map.balanceL*
fosskers Jun 25, 2019
e6be7bd
Map.balanceR*
fosskers Jun 25, 2019
15e50e8
Add `Set.fold{l,r}1`
Ericson2314 Jul 11, 2019
3b858c3
Add non-empty to/from list functions for NonEmptySet
Ericson2314 Jul 11, 2019
bbfe5be
Fix INLINABLE to respect CPP
Ericson2314 Jul 11, 2019
70ce2c0
Merge remote-tracking branch 'upstream/master' into non-empty
Ericson2314 Jul 11, 2019
3b3a1a5
Fix 7.6 build failure
Ericson2314 Jul 11, 2019
bd2dcb2
Map.insert*
Ericson2314 Jul 13, 2019
da07251
Non-empty delete/update methods
Ericson2314 Jul 15, 2019
d71be59
Map.union*NE
Ericson2314 Jul 16, 2019
4246787
NonEmptyMap: Convert more functions
Ericson2314 Jul 16, 2019
2613ecb
Fix complete pragmas
alexfmpe Oct 14, 2019
68b31c9
Update containers/src/Data/Map/Internal.hs
Ericson2314 Oct 19, 2019
344390b
Merge remote-tracking branch 'originalNonFork/master' into non-empty
Jan 9, 2020
d8acf00
add foldable instance
Jan 9, 2020
f3490fb
Add remaining NonEmptySet functions
Jan 13, 2020
4f674f4
Merge pull request #1 from obsidiansystems/non-empty-foldable
cardenaso11 Jan 13, 2020
a5a19c4
Export foldr1By and add left and strict variants
Jan 13, 2020
3f5f231
Progress on NonEmptyMap
Jan 14, 2020
3595fb4
Merge branch 'master' into non-empty
alexfmpe Sep 27, 2022
9bd5a22
Remove CPP redundant since bump to ghc 8.0
alexfmpe Sep 27, 2022
5aad8ea
Merge branch 'ghc8.0-leftovers' into non-empty
alexfmpe Sep 27, 2022
6564ead
Remove redundant CPP
alexfmpe Sep 27, 2022
91c77e8
Add type role for NonEmptyMap
alexfmpe Sep 27, 2022
3239184
Merge pull request #2 from alexfmpe/non-empty
Ericson2314 Sep 27, 2022
375e7c2
Merge branch 'master' into non-empty
alexfmpe Nov 6, 2022
7a0acbb
Fix build in ghc 9.4
alexfmpe Oct 4, 2022
3ae0075
Merge pull request #3 from alexfmpe/non-empty
Ericson2314 Nov 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions containers-tests/benchmarks/LookupGE/LookupGE_Map.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ lookupGE2 :: Ord k => k -> Map k a -> Maybe (k,a)
lookupGE2 = go
where
go !_ Tip = Nothing
go !k (Bin _ kx x l r) =
go !k (NE (Bin' _ kx x l r)) =
case compare k kx of
LT -> case go k l of
Nothing -> Just (kx,x)
ret -> ret
ret -> ret
GT -> go k r
EQ -> Just (kx,x)
{-# INLINABLE lookupGE2 #-}
Expand All @@ -27,7 +27,7 @@ lookupGE3 :: Ord k => k -> Map k a -> Maybe (k,a)
lookupGE3 = go Nothing
where
go def !_ Tip = def
go def !k (Bin _ kx x l r) =
go def !k (NE (Bin' _ kx x l r)) =
case compare k kx of
LT -> go (Just (kx,x)) k l
GT -> go def k r
Expand All @@ -38,26 +38,26 @@ lookupGE4 :: Ord k => k -> Map k a -> Maybe (k,a)
lookupGE4 k = k `seq` goNothing
where
goNothing Tip = Nothing
goNothing (Bin _ kx x l r) = case compare k kx of
LT -> goJust kx x l
EQ -> Just (kx, x)
GT -> goNothing r
goNothing (NE (Bin' _ kx x l r)) = case compare k kx of
LT -> goJust kx x l
EQ -> Just (kx, x)
GT -> goNothing r

goJust ky y Tip = Just (ky, y)
goJust ky y (Bin _ kx x l r) = case compare k kx of
LT -> goJust kx x l
EQ -> Just (kx, x)
GT -> goJust ky y r
goJust ky y (NE (Bin' _ kx x l r)) = case compare k kx of
LT -> goJust kx x l
EQ -> Just (kx, x)
GT -> goJust ky y r
{-# INLINABLE lookupGE4 #-}

-------------------------------------------------------------------------------
-- Utilities
-------------------------------------------------------------------------------

findMinMaybe :: Map k a -> Maybe (k,a)
findMinMaybe (Bin _ kx x Tip _) = Just (kx,x)
findMinMaybe (Bin _ _ _ l _) = findMinMaybe l
findMinMaybe Tip = Nothing
findMinMaybe (NE (Bin' _ kx x Tip _)) = Just (kx,x)
findMinMaybe (NE (Bin' _ _ _ l _)) = findMinMaybe l
findMinMaybe Tip = Nothing

#ifdef TESTING
-------------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions containers-tests/tests/map-properties.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Data.Map.Merge.Strict
import Data.Map.Lazy as Data.Map hiding (showTree, showTreeWith)
import Data.Map.Merge.Lazy
#endif
import Data.Map.Internal (Map (..), link2, link, bin)
import Data.Map.Internal (Map (..), NonEmptyMap(..), link2, link, bin)
import Data.Map.Internal.Debug (showTree, showTreeWith, balanced)

import Control.Applicative (Const(Const, getConst), pure, (<$>), (<*>))
Expand Down Expand Up @@ -332,15 +332,15 @@ mkArb step n
vOuter <- liftGen arbitrary
vInner <- liftGen arbitrary
if dir
then return (Bin 2 q vOuter (singleton p vInner) Tip)
else return (Bin 2 p vOuter Tip (singleton q vInner))
then return (NE (Bin' 2 q vOuter (singleton p vInner) Tip))
else return (NE (Bin' 2 p vOuter Tip (singleton q vInner)))
| otherwise = do
-- This assumes a balance factor of delta = 3
let upper = (3*(n - 1)) `quot` 4
let lower = (n + 2) `quot` 4
ln <- liftGen $ choose (lower, upper)
let rn = n - ln - 1
liftM4 (\lt x v rt -> Bin n x v lt rt) (mkArb step ln) step (liftGen arbitrary) (mkArb step rn)
liftM4 (\lt x v rt -> NE (Bin' n x v lt rt)) (mkArb step ln) step (liftGen arbitrary) (mkArb step rn)

-- A type with a peculiar Eq instance designed to make sure keys
-- come from where they're supposed to.
Expand Down
6 changes: 3 additions & 3 deletions containers-tests/tests/set-properties.hs
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,15 @@ mkArb step n
p <- step
q <- step
if dir
then return (Bin 2 q (singleton p) Tip)
else return (Bin 2 p Tip (singleton q))
then return (NE $ Bin' 2 q (singleton p) Tip)
else return (NE $ Bin' 2 p Tip (singleton q))
| otherwise = do
-- This assumes a balance factor of delta = 3
let upper = (3*(n - 1)) `quot` 4
let lower = (n + 2) `quot` 4
ln <- liftGen $ choose (lower, upper)
let rn = n - ln - 1
liftM3 (\lt x rt -> Bin n x lt rt) (mkArb step ln) step (mkArb step rn)
liftM3 (\lt x rt -> NE $ Bin' n x lt rt) (mkArb step ln) step (mkArb step rn)

-- | Given a strictly increasing list of elements, produce an arbitrarily
-- shaped set with exactly those elements.
Expand Down
Loading