Skip to content

Commit ddd24d9

Browse files
authored
Remove strict compose versions (#745)
…as discussed in haskell-unordered-containers/unordered-containers#299 (comment).
1 parent b64a103 commit ddd24d9

File tree

4 files changed

+10
-42
lines changed

4 files changed

+10
-42
lines changed

containers/src/Data/IntMap/Internal.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,10 @@ disjoint t1@(Bin p1 m1 l1 r1) t2@(Bin p2 m2 l2 r2)
783783
-- ('compose' bc ab '!?') = (bc '!?') <=< (ab '!?')
784784
-- @
785785
--
786+
-- __Note:__ Prior to UNRELEASED, "Data.IntMap.Strict" exposed a version of
787+
-- 'compose' that forced the values of the output 'IntMap'. This version does
788+
-- not force these values.
789+
--
786790
-- @since 0.6.3.1
787791
compose :: IntMap c -> IntMap Int -> IntMap c
788792
compose bc !ab

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

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ import Data.IntMap.Internal
293293
, foldrWithKey'
294294
, keysSet
295295
, mergeWithKey'
296+
, compose
296297
, delete
297298
, deleteMin
298299
, deleteMax
@@ -718,27 +719,6 @@ intersectionWithKey :: (Key -> a -> b -> c) -> IntMap a -> IntMap b -> IntMap c
718719
intersectionWithKey f m1 m2
719720
= mergeWithKey' bin (\(Tip k1 x1) (Tip _k2 x2) -> Tip k1 $! f k1 x1 x2) (const Nil) (const Nil) m1 m2
720721

721-
{--------------------------------------------------------------------
722-
Compose
723-
--------------------------------------------------------------------}
724-
-- | Relate the keys of one map to the values of
725-
-- the other, by using the values of the former as keys for lookups
726-
-- in the latter.
727-
--
728-
-- Complexity: \( O(n * \min(m,W)) \), where \(m\) is the size of the first argument
729-
--
730-
-- > compose (fromList [('a', "A"), ('b', "B")]) (fromList [(1,'a'),(2,'b'),(3,'z')]) = fromList [(1,"A"),(2,"B")]
731-
--
732-
-- @
733-
-- ('compose' bc ab '!?') = (bc '!?') <=< (ab '!?')
734-
-- @
735-
--
736-
-- @since 0.6.3.1
737-
compose :: IntMap c -> IntMap Int -> IntMap c
738-
compose bc !ab
739-
| null bc = empty
740-
| otherwise = mapMaybe (bc !?) ab
741-
742722
{--------------------------------------------------------------------
743723
MergeWithKey
744724
--------------------------------------------------------------------}

containers/src/Data/Map/Internal.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,6 +2106,10 @@ disjoint (Bin _ k _ l r) t
21062106
-- ('compose' bc ab '!?') = (bc '!?') <=< (ab '!?')
21072107
-- @
21082108
--
2109+
-- __Note:__ Prior to UNRELEASED, "Data.Map.Strict" exposed a version of
2110+
-- 'compose' that forced the values of the output 'Map'. This version does not
2111+
-- force these values.
2112+
--
21092113
-- @since 0.6.3.1
21102114
compose :: Ord b => Map b c -> Map a b -> Map a c
21112115
compose bc !ab

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

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ import Data.Map.Internal
335335
, balance
336336
, balanceL
337337
, balanceR
338+
, compose
338339
, elemAt
339340
, elems
340341
, empty
@@ -1205,27 +1206,6 @@ forceMaybe Nothing = Nothing
12051206
forceMaybe m@(Just !_) = m
12061207
{-# INLINE forceMaybe #-}
12071208

1208-
{--------------------------------------------------------------------
1209-
Compose
1210-
--------------------------------------------------------------------}
1211-
-- | Relate the keys of one map to the values of
1212-
-- the other, by using the values of the former as keys for lookups
1213-
-- in the latter.
1214-
--
1215-
-- Complexity: \( O (n * \log(m)) \), where \(m\) is the size of the first argument
1216-
--
1217-
-- > compose (fromList [('a', "A"), ('b', "B")]) (fromList [(1,'a'),(2,'b'),(3,'z')]) = fromList [(1,"A"),(2,"B")]
1218-
--
1219-
-- @
1220-
-- ('compose' bc ab '!?') = (bc '!?') <=< (ab '!?')
1221-
-- @
1222-
--
1223-
-- @since 0.6.3.1
1224-
compose :: Ord b => Map b c -> Map a b -> Map a c
1225-
compose bc !ab
1226-
| null bc = empty
1227-
| otherwise = mapMaybe (bc !?) ab
1228-
12291209
{--------------------------------------------------------------------
12301210
MergeWithKey
12311211
--------------------------------------------------------------------}

0 commit comments

Comments
 (0)