Skip to content

Commit ec6d6e4

Browse files
authored
Define a common StrictTriple for internal use (#1170)
* Remove the currently unused strict Maybe * Move StrictPair to Utils.Containers.Internal.Strict next to StrictTriple
1 parent e51597b commit ec6d6e4

File tree

12 files changed

+44
-79
lines changed

12 files changed

+44
-79
lines changed

containers-tests/containers-tests.cabal

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,12 @@ library
114114
Data.Tree
115115
Utils.Containers.Internal.BitQueue
116116
Utils.Containers.Internal.BitUtil
117-
Utils.Containers.Internal.StrictPair
118117

119118
other-modules:
120119
Utils.Containers.Internal.Prelude
121120
Utils.Containers.Internal.PtrEquality
122121
Utils.Containers.Internal.State
123-
Utils.Containers.Internal.StrictMaybe
122+
Utils.Containers.Internal.Strict
124123
Utils.Containers.Internal.EqOrdUtil
125124

126125
if impl(ghc >= 8.6)

containers/containers.cabal

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,10 @@ Library
8181
other-modules:
8282
Utils.Containers.Internal.Prelude
8383
Utils.Containers.Internal.State
84-
Utils.Containers.Internal.StrictMaybe
84+
Utils.Containers.Internal.Strict
8585
Utils.Containers.Internal.PtrEquality
8686
Utils.Containers.Internal.EqOrdUtil
8787
Utils.Containers.Internal.BitUtil
8888
Utils.Containers.Internal.BitQueue
89-
Utils.Containers.Internal.StrictPair
9089

9190
include-dirs: include

containers/src/Data/IntMap/Internal.hs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,8 @@ import Data.IntSet.Internal.IntTreeCommons
347347
, Order(..)
348348
)
349349
import Utils.Containers.Internal.BitUtil (shiftLL, shiftRL, iShiftRL, wordSize)
350-
import Utils.Containers.Internal.StrictPair
350+
import Utils.Containers.Internal.Strict
351+
(StrictPair(..), StrictTriple(..), toPair)
351352

352353
#ifdef __GLASGOW_HASKELL__
353354
import Data.Coerce
@@ -2974,14 +2975,14 @@ split k t =
29742975
go _ Nil = (Nil :*: Nil)
29752976

29762977

2977-
data SplitLookup a = SplitLookup !(IntMap a) !(Maybe a) !(IntMap a)
2978+
type SplitLookup a = StrictTriple (IntMap a) (Maybe a) (IntMap a)
29782979

29792980
mapLT :: (IntMap a -> IntMap a) -> SplitLookup a -> SplitLookup a
2980-
mapLT f (SplitLookup lt fnd gt) = SplitLookup (f lt) fnd gt
2981+
mapLT f (TripleS lt fnd gt) = TripleS (f lt) fnd gt
29812982
{-# INLINE mapLT #-}
29822983

29832984
mapGT :: (IntMap a -> IntMap a) -> SplitLookup a -> SplitLookup a
2984-
mapGT f (SplitLookup lt fnd gt) = SplitLookup lt fnd (f gt)
2985+
mapGT f (TripleS lt fnd gt) = TripleS lt fnd (f gt)
29852986
{-# INLINE mapGT #-}
29862987

29872988
-- | \(O(\min(n,W))\). Performs a 'split' but also returns whether the pivot
@@ -3003,20 +3004,20 @@ splitLookup k t =
30033004
then mapLT (\l' -> binCheckL p l' r) (go k l)
30043005
else mapGT (binCheckR p l) (go k r)
30053006
_ -> go k t
3006-
of SplitLookup lt fnd gt -> (lt, fnd, gt)
3007+
of TripleS lt fnd gt -> (lt, fnd, gt)
30073008
where
30083009
go !k' t'@(Bin p l r)
30093010
| nomatch k' p =
30103011
if k' < unPrefix p
3011-
then SplitLookup Nil Nothing t'
3012-
else SplitLookup t' Nothing Nil
3012+
then TripleS Nil Nothing t'
3013+
else TripleS t' Nothing Nil
30133014
| left k' p = mapGT (\l' -> binCheckL p l' r) (go k' l)
30143015
| otherwise = mapLT (binCheckR p l) (go k' r)
30153016
go k' t'@(Tip ky y)
3016-
| k' > ky = SplitLookup t' Nothing Nil
3017-
| k' < ky = SplitLookup Nil Nothing t'
3018-
| otherwise = SplitLookup Nil (Just y) Nil
3019-
go _ Nil = SplitLookup Nil Nothing Nil
3017+
| k' > ky = TripleS t' Nothing Nil
3018+
| k' < ky = TripleS Nil Nothing t'
3019+
| otherwise = TripleS Nil (Just y) Nil
3020+
go _ Nil = TripleS Nil Nothing Nil
30203021

30213022
{--------------------------------------------------------------------
30223023
Fold

containers/src/Data/IntMap/Strict/Internal.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ import Data.IntMap.Internal
329329
)
330330
import qualified Data.IntSet.Internal as IntSet
331331
import Utils.Containers.Internal.BitUtil (iShiftRL, shiftLL, shiftRL)
332-
import Utils.Containers.Internal.StrictPair
332+
import Utils.Containers.Internal.Strict (StrictPair(..), toPair)
333333
import qualified Data.Foldable as Foldable
334334
import Data.Functor.Identity (Identity (..))
335335

containers/src/Data/IntSet/Internal.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ import Utils.Containers.Internal.Prelude hiding
203203
import Prelude ()
204204

205205
import Utils.Containers.Internal.BitUtil (iShiftRL, shiftLL, shiftRL)
206-
import Utils.Containers.Internal.StrictPair
206+
import Utils.Containers.Internal.Strict (StrictPair(..), toPair)
207207
import Data.IntSet.Internal.IntTreeCommons
208208
( Key
209209
, Prefix(..)

containers/src/Data/Map/Internal.hs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ module Data.Map.Internal (
365365
, ascLinkAll
366366
, descLinkTop
367367
, descLinkAll
368-
, MaybeS(..)
369368
, Identity(..)
370369
, Stack(..)
371370
, foldl'Stack
@@ -403,8 +402,8 @@ import Prelude ()
403402
import qualified Data.Set.Internal as Set
404403
import Data.Set.Internal (Set)
405404
import Utils.Containers.Internal.PtrEquality (ptrEq)
406-
import Utils.Containers.Internal.StrictPair
407-
import Utils.Containers.Internal.StrictMaybe
405+
import Utils.Containers.Internal.Strict
406+
(StrictPair(..), StrictTriple(..), toPair)
408407
import Utils.Containers.Internal.BitQueue
409408
import Utils.Containers.Internal.EqOrdUtil (EqM(..), OrdM(..))
410409
#ifdef DEFINE_ALTERF_FALLBACK
@@ -3976,20 +3975,20 @@ split !k0 t0 = toPair $ go k0 t0
39763975
-- > splitLookup 6 (fromList [(5,"a"), (3,"b")]) == (fromList [(3,"b"), (5,"a")], Nothing, empty)
39773976
splitLookup :: Ord k => k -> Map k a -> (Map k a,Maybe a,Map k a)
39783977
splitLookup k0 m = case go k0 m of
3979-
StrictTriple l mv r -> (l, mv, r)
3978+
TripleS l mv r -> (l, mv, r)
39803979
where
39813980
go :: Ord k => k -> Map k a -> StrictTriple (Map k a) (Maybe a) (Map k a)
39823981
go !k t =
39833982
case t of
3984-
Tip -> StrictTriple Tip Nothing Tip
3983+
Tip -> TripleS Tip Nothing Tip
39853984
Bin _ kx x l r -> case compare k kx of
3986-
LT -> let StrictTriple lt z gt = go k l
3985+
LT -> let TripleS lt z gt = go k l
39873986
!gt' = linkR kx x gt r
3988-
in StrictTriple lt z gt'
3989-
GT -> let StrictTriple lt z gt = go k r
3987+
in TripleS lt z gt'
3988+
GT -> let TripleS lt z gt = go k r
39903989
!lt' = linkL kx x l lt
3991-
in StrictTriple lt' z gt
3992-
EQ -> StrictTriple l (Just x) r
3990+
in TripleS lt' z gt
3991+
EQ -> TripleS l (Just x) r
39933992
#if __GLASGOW_HASKELL__
39943993
{-# INLINABLE splitLookup #-}
39953994
#endif
@@ -4000,26 +3999,24 @@ splitLookup k0 m = case go k0 m of
40003999
-- constructors.
40014000
splitMember :: Ord k => k -> Map k a -> (Map k a,Bool,Map k a)
40024001
splitMember k0 m = case go k0 m of
4003-
StrictTriple l mv r -> (l, mv, r)
4002+
TripleS l mv r -> (l, mv, r)
40044003
where
40054004
go :: Ord k => k -> Map k a -> StrictTriple (Map k a) Bool (Map k a)
40064005
go !k t =
40074006
case t of
4008-
Tip -> StrictTriple Tip False Tip
4007+
Tip -> TripleS Tip False Tip
40094008
Bin _ kx x l r -> case compare k kx of
4010-
LT -> let StrictTriple lt z gt = go k l
4009+
LT -> let TripleS lt z gt = go k l
40114010
!gt' = linkR kx x gt r
4012-
in StrictTriple lt z gt'
4013-
GT -> let StrictTriple lt z gt = go k r
4011+
in TripleS lt z gt'
4012+
GT -> let TripleS lt z gt = go k r
40144013
!lt' = linkL kx x l lt
4015-
in StrictTriple lt' z gt
4016-
EQ -> StrictTriple l True r
4014+
in TripleS lt' z gt
4015+
EQ -> TripleS l True r
40174016
#if __GLASGOW_HASKELL__
40184017
{-# INLINABLE splitMember #-}
40194018
#endif
40204019

4021-
data StrictTriple a b c = StrictTriple !a !b !c
4022-
40234020
{--------------------------------------------------------------------
40244021
MapBuilder
40254022
--------------------------------------------------------------------}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ import Control.Applicative (Const (..), liftA3)
415415
import Data.Semigroup (Arg (..))
416416
import qualified Data.Set.Internal as Set
417417
import qualified Data.Map.Internal as L
418-
import Utils.Containers.Internal.StrictPair
418+
import Utils.Containers.Internal.Strict (StrictPair(..), toPair)
419419

420420
#ifdef __GLASGOW_HASKELL__
421421
import Data.Coerce

containers/src/Data/Sequence/Internal.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ import qualified Data.Array
232232

233233
import Data.Functor.Identity (Identity(..))
234234

235-
import Utils.Containers.Internal.StrictPair (StrictPair (..), toPair)
235+
import Utils.Containers.Internal.Strict (StrictPair (..), toPair)
236236
import Control.Monad.Zip (MonadZip (..))
237237
import Control.Monad.Fix (MonadFix (..), fix)
238238

containers/src/Data/Set/Internal.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ import qualified Data.Foldable as Foldable
241241
import Control.DeepSeq (NFData(rnf),NFData1(liftRnf))
242242
import Data.List.NonEmpty (NonEmpty(..))
243243

244-
import Utils.Containers.Internal.StrictPair
244+
import Utils.Containers.Internal.Strict (StrictPair(..), toPair)
245245
import Utils.Containers.Internal.PtrEquality
246246
import Utils.Containers.Internal.EqOrdUtil (EqM(..), OrdM(..))
247247

containers/src/Utils/Containers/Internal/EqOrdUtil.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Utils.Containers.Internal.EqOrdUtil
77
#if !MIN_VERSION_base(4,11,0)
88
import Data.Semigroup (Semigroup(..))
99
#endif
10-
import Utils.Containers.Internal.StrictPair
10+
import Utils.Containers.Internal.Strict (StrictPair(..))
1111

1212
newtype EqM a = EqM { runEqM :: a -> StrictPair Bool a }
1313

0 commit comments

Comments
 (0)