@@ -288,8 +288,8 @@ module Data.IntMap.Internal (
288
288
, link
289
289
, linkKey
290
290
, bin
291
- , binCheckLeft
292
- , binCheckRight
291
+ , binCheckL
292
+ , binCheckR
293
293
, MonoState (.. )
294
294
, Stack (.. )
295
295
, ascLinkTop
@@ -954,8 +954,8 @@ insertLookupWithKey _ k x Nil = (Nothing,Tip k x)
954
954
delete :: Key -> IntMap a -> IntMap a
955
955
delete ! k t@ (Bin p l r)
956
956
| nomatch k p = t
957
- | left k p = binCheckLeft p (delete k l) r
958
- | otherwise = binCheckRight p l (delete k r)
957
+ | left k p = binCheckL p (delete k l) r
958
+ | otherwise = binCheckR p l (delete k r)
959
959
delete k t@ (Tip ky _)
960
960
| k == ky = Nil
961
961
| otherwise = t
@@ -1014,8 +1014,8 @@ update f
1014
1014
1015
1015
updateWithKey :: (Key -> a -> Maybe a ) -> Key -> IntMap a -> IntMap a
1016
1016
updateWithKey f ! k (Bin p l r)
1017
- | left k p = binCheckLeft p (updateWithKey f k l) r
1018
- | otherwise = binCheckRight p l (updateWithKey f k r)
1017
+ | left k p = binCheckL p (updateWithKey f k l) r
1018
+ | otherwise = binCheckR p l (updateWithKey f k r)
1019
1019
updateWithKey f k t@ (Tip ky y)
1020
1020
| k == ky = case (f k y) of
1021
1021
Just y' -> Tip ky y'
@@ -1036,9 +1036,9 @@ updateWithKey _ _ Nil = Nil
1036
1036
updateLookupWithKey :: (Key -> a -> Maybe a ) -> Key -> IntMap a -> (Maybe a ,IntMap a )
1037
1037
updateLookupWithKey f ! k (Bin p l r)
1038
1038
| left k p = let ! (found,l') = updateLookupWithKey f k l
1039
- in (found,binCheckLeft p l' r)
1039
+ in (found,binCheckL p l' r)
1040
1040
| otherwise = let ! (found,r') = updateLookupWithKey f k r
1041
- in (found,binCheckRight p l r')
1041
+ in (found,binCheckR p l r')
1042
1042
updateLookupWithKey f k t@ (Tip ky y)
1043
1043
| k== ky = case (f k y) of
1044
1044
Just y' -> (Just y,Tip ky y')
@@ -1056,8 +1056,8 @@ alter f !k t@(Bin p l r)
1056
1056
| nomatch k p = case f Nothing of
1057
1057
Nothing -> t
1058
1058
Just x -> linkKey k (Tip k x) p t
1059
- | left k p = binCheckLeft p (alter f k l) r
1060
- | otherwise = binCheckRight p l (alter f k r)
1059
+ | left k p = binCheckL p (alter f k l) r
1060
+ | otherwise = binCheckR p l (alter f k r)
1061
1061
alter f k t@ (Tip ky y)
1062
1062
| k== ky = case f (Just y) of
1063
1063
Just x -> Tip ky x
@@ -1211,8 +1211,8 @@ differenceWithKey f m1 m2
1211
1211
-- @since 0.5.8
1212
1212
withoutKeys :: IntMap a -> IntSet -> IntMap a
1213
1213
withoutKeys t1@ (Bin p1 l1 r1) t2@ (IntSet. Bin p2 l2 r2) = case treeTreeBranch p1 p2 of
1214
- ABL -> binCheckLeft p1 (withoutKeys l1 t2) r1
1215
- ABR -> binCheckRight p1 l1 (withoutKeys r1 t2)
1214
+ ABL -> binCheckL p1 (withoutKeys l1 t2) r1
1215
+ ABR -> binCheckR p1 l1 (withoutKeys r1 t2)
1216
1216
BAL -> withoutKeys t1 l2
1217
1217
BAR -> withoutKeys t1 r2
1218
1218
EQL -> bin p1 (withoutKeys l1 l2) (withoutKeys r1 r2)
@@ -1232,8 +1232,8 @@ withoutKeysTip t@(Bin p l r) !p2 !bm2
1232
1232
then restrictBM t (complement bm2)
1233
1233
else t
1234
1234
| nomatch p2 p = t
1235
- | left p2 p = binCheckLeft p (withoutKeysTip l p2 bm2) r
1236
- | otherwise = binCheckRight p l (withoutKeysTip r p2 bm2)
1235
+ | left p2 p = binCheckL p (withoutKeysTip l p2 bm2) r
1236
+ | otherwise = binCheckR p l (withoutKeysTip r p2 bm2)
1237
1237
withoutKeysTip t@ (Tip kx _) ! p2 ! bm2
1238
1238
| IntSet. prefixOf kx == p2 && IntSet. bitmapOf kx .&. bm2 /= 0 = Nil
1239
1239
| otherwise = t
@@ -1358,10 +1358,10 @@ intersectionWithKey f m1 m2
1358
1358
symmetricDifference :: IntMap a -> IntMap a -> IntMap a
1359
1359
symmetricDifference t1@ (Bin p1 l1 r1) t2@ (Bin p2 l2 r2) =
1360
1360
case treeTreeBranch p1 p2 of
1361
- ABL -> bin p1 (symmetricDifference l1 t2) r1
1362
- ABR -> bin p1 l1 (symmetricDifference r1 t2)
1363
- BAL -> bin p2 (symmetricDifference t1 l2) r2
1364
- BAR -> bin p2 l2 (symmetricDifference t1 r2)
1361
+ ABL -> binCheckL p1 (symmetricDifference l1 t2) r1
1362
+ ABR -> binCheckR p1 l1 (symmetricDifference r1 t2)
1363
+ BAL -> binCheckL p2 (symmetricDifference t1 l2) r2
1364
+ BAR -> binCheckR p2 l2 (symmetricDifference t1 r2)
1365
1365
EQL -> bin p1 (symmetricDifference l1 l2) (symmetricDifference r1 r2)
1366
1366
NOM -> link (unPrefix p1) t1 (unPrefix p2) t2
1367
1367
symmetricDifference t1@ (Bin _ _ _) t2@ (Tip k2 _) = symDiffTip t2 k2 t1
@@ -1374,8 +1374,8 @@ symDiffTip !t1 !k1 = go
1374
1374
where
1375
1375
go t2@ (Bin p2 l2 r2)
1376
1376
| nomatch k1 p2 = linkKey k1 t1 p2 t2
1377
- | left k1 p2 = bin p2 (go l2) r2
1378
- | otherwise = bin p2 l2 (go r2)
1377
+ | left k1 p2 = binCheckL p2 (go l2) r2
1378
+ | otherwise = binCheckR p2 l2 (go r2)
1379
1379
go t2@ (Tip k2 _)
1380
1380
| k1 == k2 = Nil
1381
1381
| otherwise = link k1 t1 k2 t2
@@ -2204,10 +2204,10 @@ mergeA
2204
2204
2205
2205
updateMinWithKey :: (Key -> a -> Maybe a ) -> IntMap a -> IntMap a
2206
2206
updateMinWithKey f t =
2207
- case t of Bin p l r | signBranch p -> binCheckRight p l (go f r)
2207
+ case t of Bin p l r | signBranch p -> binCheckR p l (go f r)
2208
2208
_ -> go f t
2209
2209
where
2210
- go f' (Bin p l r) = binCheckLeft p (go f' l) r
2210
+ go f' (Bin p l r) = binCheckL p (go f' l) r
2211
2211
go f' (Tip k y) = case f' k y of
2212
2212
Just y' -> Tip k y'
2213
2213
Nothing -> Nil
@@ -2220,10 +2220,10 @@ updateMinWithKey f t =
2220
2220
2221
2221
updateMaxWithKey :: (Key -> a -> Maybe a ) -> IntMap a -> IntMap a
2222
2222
updateMaxWithKey f t =
2223
- case t of Bin p l r | signBranch p -> binCheckLeft p (go f l) r
2223
+ case t of Bin p l r | signBranch p -> binCheckL p (go f l) r
2224
2224
_ -> go f t
2225
2225
where
2226
- go f' (Bin p l r) = binCheckRight p l (go f' r)
2226
+ go f' (Bin p l r) = binCheckR p l (go f' r)
2227
2227
go f' (Tip k y) = case f' k y of
2228
2228
Just y' -> Tip k y'
2229
2229
Nothing -> Nil
@@ -2250,11 +2250,11 @@ maxViewWithKeySure t =
2250
2250
case t of
2251
2251
Nil -> error " maxViewWithKeySure Nil"
2252
2252
Bin p l r | signBranch p ->
2253
- case go l of View k a l' -> View k a (binCheckLeft p l' r)
2253
+ case go l of View k a l' -> View k a (binCheckL p l' r)
2254
2254
_ -> go t
2255
2255
where
2256
2256
go (Bin p l r) =
2257
- case go r of View k a r' -> View k a (binCheckRight p l r')
2257
+ case go r of View k a r' -> View k a (binCheckR p l r')
2258
2258
go (Tip k y) = View k y Nil
2259
2259
go Nil = error " maxViewWithKey_go Nil"
2260
2260
-- See note on NOINLINE at minViewWithKeySure
@@ -2284,11 +2284,11 @@ minViewWithKeySure t =
2284
2284
Nil -> error " minViewWithKeySure Nil"
2285
2285
Bin p l r | signBranch p ->
2286
2286
case go r of
2287
- View k a r' -> View k a (binCheckRight p l r')
2287
+ View k a r' -> View k a (binCheckR p l r')
2288
2288
_ -> go t
2289
2289
where
2290
2290
go (Bin p l r) =
2291
- case go l of View k a l' -> View k a (binCheckLeft p l' r)
2291
+ case go l of View k a l' -> View k a (binCheckL p l' r)
2292
2292
go (Tip k y) = View k y Nil
2293
2293
go Nil = error " minViewWithKey_go Nil"
2294
2294
-- There's never anything significant to be gained by inlining
@@ -2758,12 +2758,12 @@ takeWhileAntitone predicate t =
2758
2758
Bin p l r
2759
2759
| signBranch p ->
2760
2760
if predicate 0 -- handle negative numbers.
2761
- then bin p (go predicate l) r
2761
+ then binCheckL p (go predicate l) r
2762
2762
else go predicate r
2763
2763
_ -> go predicate t
2764
2764
where
2765
2765
go predicate' (Bin p l r)
2766
- | predicate' (unPrefix p) = bin p l (go predicate' r)
2766
+ | predicate' (unPrefix p) = binCheckR p l (go predicate' r)
2767
2767
| otherwise = go predicate' l
2768
2768
go predicate' t'@ (Tip ky _)
2769
2769
| predicate' ky = t'
@@ -2787,12 +2787,12 @@ dropWhileAntitone predicate t =
2787
2787
| signBranch p ->
2788
2788
if predicate 0 -- handle negative numbers.
2789
2789
then go predicate l
2790
- else bin p l (go predicate r)
2790
+ else binCheckR p l (go predicate r)
2791
2791
_ -> go predicate t
2792
2792
where
2793
2793
go predicate' (Bin p l r)
2794
2794
| predicate' (unPrefix p) = go predicate' r
2795
- | otherwise = bin p (go predicate' l) r
2795
+ | otherwise = binCheckL p (go predicate' l) r
2796
2796
go predicate' t'@ (Tip ky _)
2797
2797
| predicate' ky = Nil
2798
2798
| otherwise = t'
@@ -2819,21 +2819,21 @@ spanAntitone predicate t =
2819
2819
then
2820
2820
case go predicate l of
2821
2821
(lt :*: gt) ->
2822
- let ! lt' = bin p lt r
2822
+ let ! lt' = binCheckL p lt r
2823
2823
in (lt', gt)
2824
2824
else
2825
2825
case go predicate r of
2826
2826
(lt :*: gt) ->
2827
- let ! gt' = bin p l gt
2827
+ let ! gt' = binCheckR p l gt
2828
2828
in (lt, gt')
2829
2829
_ -> case go predicate t of
2830
2830
(lt :*: gt) -> (lt, gt)
2831
2831
where
2832
2832
go predicate' (Bin p l r)
2833
2833
| predicate' (unPrefix p)
2834
- = case go predicate' r of (lt :*: gt) -> bin p l lt :*: gt
2834
+ = case go predicate' r of (lt :*: gt) -> binCheckR p l lt :*: gt
2835
2835
| otherwise
2836
- = case go predicate' l of (lt :*: gt) -> lt :*: bin p gt r
2836
+ = case go predicate' l of (lt :*: gt) -> lt :*: binCheckL p gt r
2837
2837
go predicate' t'@ (Tip ky _)
2838
2838
| predicate' ky = (t' :*: Nil )
2839
2839
| otherwise = (Nil :*: t')
@@ -2914,20 +2914,20 @@ split k t =
2914
2914
then
2915
2915
case go k l of
2916
2916
(lt :*: gt) ->
2917
- let ! lt' = bin p lt r
2917
+ let ! lt' = binCheckL p lt r
2918
2918
in (lt', gt)
2919
2919
else
2920
2920
case go k r of
2921
2921
(lt :*: gt) ->
2922
- let ! gt' = bin p l gt
2922
+ let ! gt' = binCheckR p l gt
2923
2923
in (lt, gt')
2924
2924
_ -> case go k t of
2925
2925
(lt :*: gt) -> (lt, gt)
2926
2926
where
2927
2927
go ! k' t'@ (Bin p l r)
2928
2928
| nomatch k' p = if k' < unPrefix p then Nil :*: t' else t' :*: Nil
2929
- | left k' p = case go k' l of (lt :*: gt) -> lt :*: bin p gt r
2930
- | otherwise = case go k' r of (lt :*: gt) -> bin p l lt :*: gt
2929
+ | left k' p = case go k' l of (lt :*: gt) -> lt :*: binCheckL p gt r
2930
+ | otherwise = case go k' r of (lt :*: gt) -> binCheckR p l lt :*: gt
2931
2931
go k' t'@ (Tip ky _)
2932
2932
| k' > ky = (t' :*: Nil )
2933
2933
| k' < ky = (Nil :*: t')
@@ -2961,8 +2961,8 @@ splitLookup k t =
2961
2961
Bin p l r
2962
2962
| signBranch p ->
2963
2963
if k >= 0 -- handle negative numbers.
2964
- then mapLT (flip (bin p) r) (go k l)
2965
- else mapGT (bin p l) (go k r)
2964
+ then mapLT (\ l' -> binCheckL p l' r) (go k l)
2965
+ else mapGT (binCheckR p l) (go k r)
2966
2966
_ -> go k t
2967
2967
of SplitLookup lt fnd gt -> (lt, fnd, gt)
2968
2968
where
@@ -2971,8 +2971,8 @@ splitLookup k t =
2971
2971
if k' < unPrefix p
2972
2972
then SplitLookup Nil Nothing t'
2973
2973
else SplitLookup t' Nothing Nil
2974
- | left k' p = mapGT (flip (bin p) r) (go k' l)
2975
- | otherwise = mapLT (bin p l) (go k' r)
2974
+ | left k' p = mapGT (\ l' -> binCheckL p l' r) (go k' l)
2975
+ | otherwise = mapLT (binCheckR p l) (go k' r)
2976
2976
go k' t'@ (Tip ky y)
2977
2977
| k' > ky = SplitLookup t' Nothing Nil
2978
2978
| k' < ky = SplitLookup Nil Nothing t'
@@ -3666,17 +3666,17 @@ bin _ Nil r = r
3666
3666
bin p l r = Bin p l r
3667
3667
{-# INLINE bin #-}
3668
3668
3669
- -- binCheckLeft only checks that the left subtree is non-empty
3670
- binCheckLeft :: Prefix -> IntMap a -> IntMap a -> IntMap a
3671
- binCheckLeft _ Nil r = r
3672
- binCheckLeft p l r = Bin p l r
3673
- {-# INLINE binCheckLeft #-}
3674
-
3675
- -- binCheckRight only checks that the right subtree is non-empty
3676
- binCheckRight :: Prefix -> IntMap a -> IntMap a -> IntMap a
3677
- binCheckRight _ l Nil = l
3678
- binCheckRight p l r = Bin p l r
3679
- {-# INLINE binCheckRight #-}
3669
+ -- binCheckL only checks that the left subtree is non-empty
3670
+ binCheckL :: Prefix -> IntMap a -> IntMap a -> IntMap a
3671
+ binCheckL _ Nil r = r
3672
+ binCheckL p l r = Bin p l r
3673
+ {-# INLINE binCheckL #-}
3674
+
3675
+ -- binCheckR only checks that the right subtree is non-empty
3676
+ binCheckR :: Prefix -> IntMap a -> IntMap a -> IntMap a
3677
+ binCheckR _ l Nil = l
3678
+ binCheckR p l r = Bin p l r
3679
+ {-# INLINE binCheckR #-}
3680
3680
3681
3681
{- -------------------------------------------------------------------
3682
3682
Utilities
0 commit comments