Skip to content

Commit 2eb64f5

Browse files
committed
General package stuff, mostly
* Rename the internals again. I think they're getting close to reasonable now. Get the cabal benchmarks running again. Deprecate the "deprecated" `IntMap` stuff. Make a `Debug` module for the `Data.Map` debugging functions. * Rewrite `Data.Map.Internal.Debug.validSize` to use the `Monad Maybe` instance for clarity.
1 parent 576fe49 commit 2eb64f5

25 files changed

+304
-293
lines changed

.travis.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,23 @@ before_install:
2828
install:
2929
- travis_retry cabal update
3030
- cabal install --only-dependencies
31-
# we need to install the test-suite deps manually as the cabal solver would
32-
# otherwise complaing about cyclic deps
31+
# we need to install the test-suite and benchmark deps manually as the cabal
32+
# solver would otherwise complain about cyclic deps
3333
- cabal install 'test-framework >= 0.3.3' 'test-framework-quickcheck2 >= 0.2.9' 'QuickCheck >= 2.4.0.1' 'ChasingBottoms' 'HUnit' 'test-framework-hunit'
3434

35+
# If we enable benchmarks, we'll need 'criterion >= 0.4.0 && < 1.2'
36+
3537
# Here starts the actual work to be performed for the package under
3638
# test; any command which exits with a non-zero exit code causes the
3739
# build to fail.
3840
script:
3941
# -v2 provides useful information for debugging
4042
- cabal configure -v2 --enable-tests
4143

44+
# We'd like to
45+
# --enable-benchmarks
46+
# but CI time goes through the roof. Maybe there's a way to limit it to just one GHC version?
47+
4248
# this builds all libraries and executables
4349
# (including tests/benchmarks)
4450
- cabal build

Data/IntMap.hs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,38 +65,33 @@ import Prelude () -- hide foldr
6565
import qualified Data.IntMap.Strict as Strict
6666
import Data.IntMap.Lazy
6767

68-
-- | /Deprecated./ As of version 0.5, replaced by
69-
-- 'Data.IntMap.Strict.insertWith'.
70-
--
71-
-- /O(log n)/. Same as 'insertWith', but the result of the combining function
68+
-- | /O(log n)/. Same as 'insertWith', but the result of the combining function
7269
-- is evaluated to WHNF before inserted to the map.
7370

71+
{-# DEPRECATED insertWith' "As of version 0.5, replaced by 'Data.IntMap.Strict.insertWith'." #-}
7472
insertWith' :: (a -> a -> a) -> Key -> a -> IntMap a -> IntMap a
7573
insertWith' = Strict.insertWith
7674

77-
-- | /Deprecated./ As of version 0.5, replaced by
78-
-- 'Data.IntMap.Strict.insertWithKey'.
79-
--
80-
-- /O(log n)/. Same as 'insertWithKey', but the result of the combining
75+
-- | /O(log n)/. Same as 'insertWithKey', but the result of the combining
8176
-- function is evaluated to WHNF before inserted to the map.
8277

78+
{-# DEPRECATED insertWithKey' "As of version 0.5, replaced by 'Data.IntMap.Strict.insertWithKey'." #-}
8379
insertWithKey' :: (Key -> a -> a -> a) -> Key -> a -> IntMap a -> IntMap a
8480
insertWithKey' = Strict.insertWithKey
8581

86-
-- | /Deprecated./ As of version 0.5, replaced by 'foldr'.
87-
--
88-
-- /O(n)/. Fold the values in the map using the given
82+
-- | /O(n)/. Fold the values in the map using the given
8983
-- right-associative binary operator. This function is an equivalent
9084
-- of 'foldr' and is present for compatibility only.
85+
{-# DEPRECATED fold "As of version 0.5, replaced by 'foldr'." #-}
9186
fold :: (a -> b -> b) -> b -> IntMap a -> b
9287
fold = foldr
9388
{-# INLINE fold #-}
9489

95-
-- | /Deprecated./ As of version 0.5, replaced by 'foldrWithKey'.
96-
--
97-
-- /O(n)/. Fold the keys and values in the map using the given
90+
-- | /O(n)/. Fold the keys and values in the map using the given
9891
-- right-associative binary operator. This function is an equivalent
9992
-- of 'foldrWithKey' and is present for compatibility only.
93+
94+
{-# DEPRECATED foldWithKey "As of version 0.5, replaced by 'foldrWithKey'." #-}
10095
foldWithKey :: (Key -> a -> b -> b) -> b -> IntMap a -> b
10196
foldWithKey = foldrWithKey
10297
{-# INLINE foldWithKey #-}

Data/IntMap/Internal.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,9 @@ import Prelude hiding (lookup, map, filter, foldr, foldl, null)
256256

257257
import Data.IntSet.Internal (Key)
258258
import qualified Data.IntSet.Internal as IntSet
259-
import Data.Utils.BitUtil
260-
import Data.Utils.StrictFold
261-
import Data.Utils.StrictPair
259+
import Utils.Containers.Internal.BitUtil
260+
import Utils.Containers.Internal.StrictFold
261+
import Utils.Containers.Internal.StrictPair
262262

263263
#if __GLASGOW_HASKELL__
264264
import Data.Data (Data(..), Constr, mkConstr, constrIndex, Fixity(Prefix),

Data/IntMap/Strict.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,9 @@ import Data.IntMap.Internal hiding
265265
)
266266

267267
import qualified Data.IntSet.Internal as IntSet
268-
import Data.Utils.BitUtil
269-
import Data.Utils.StrictFold
270-
import Data.Utils.StrictPair
268+
import Utils.Containers.Internal.BitUtil
269+
import Utils.Containers.Internal.StrictFold
270+
import Utils.Containers.Internal.StrictPair
271271
#if __GLASGOW_HASKELL__ >= 709
272272
import Data.Coerce
273273
#endif

Data/IntSet/Internal.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ import Data.Semigroup (Semigroup((<>), stimes), stimesIdempotentMonoid)
194194
import Data.Typeable
195195
import Prelude hiding (filter, foldr, foldl, null, map)
196196

197-
import Data.Utils.BitUtil
198-
import Data.Utils.StrictFold
199-
import Data.Utils.StrictPair
197+
import Utils.Containers.Internal.BitUtil
198+
import Utils.Containers.Internal.StrictFold
199+
import Utils.Containers.Internal.StrictPair
200200

201201
#if __GLASGOW_HASKELL__
202202
import Data.Data (Data(..), Constr, mkConstr, constrIndex, Fixity(Prefix), DataType, mkDataType)

Data/Map/Internal.hs

Lines changed: 6 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,6 @@ module Data.Map.Internal (
327327
, minViewWithKey
328328
, maxViewWithKey
329329

330-
-- * Debugging
331-
, showTree
332-
, showTreeWith
333-
, valid
334-
335330
-- Used by the strict version
336331
, AreWeStrict (..)
337332
, atKeyImpl
@@ -340,7 +335,6 @@ module Data.Map.Internal (
340335
#endif
341336
, bin
342337
, balance
343-
, balanced
344338
, balanceL
345339
, balanceR
346340
, delta
@@ -380,13 +374,13 @@ import Prelude hiding (lookup, map, filter, foldr, foldl, null, splitAt, take, d
380374

381375
import qualified Data.Set.Internal as Set
382376
import Data.Set.Internal (Set)
383-
import Data.Utils.PtrEquality (ptrEq)
384-
import Data.Utils.StrictFold
385-
import Data.Utils.StrictPair
386-
import Data.Utils.StrictMaybe
387-
import Data.Utils.BitQueue
377+
import Utils.Containers.Internal.PtrEquality (ptrEq)
378+
import Utils.Containers.Internal.StrictFold
379+
import Utils.Containers.Internal.StrictPair
380+
import Utils.Containers.Internal.StrictMaybe
381+
import Utils.Containers.Internal.BitQueue
388382
#if DEFINE_ALTERF_FALLBACK
389-
import Data.Utils.BitUtil (wordSize)
383+
import Utils.Containers.Internal.BitUtil (wordSize)
390384
#endif
391385

392386
#if __GLASGOW_HASKELL__
@@ -3961,148 +3955,12 @@ instance (Show k, Show a) => Show (Map k a) where
39613955
showsPrec d m = showParen (d > 10) $
39623956
showString "fromList " . shows (toList m)
39633957

3964-
-- | /O(n)/. Show the tree that implements the map. The tree is shown
3965-
-- in a compressed, hanging format. See 'showTreeWith'.
3966-
{-# DEPRECATED showTree "This function is being removed from the public API." #-}
3967-
showTree :: (Show k,Show a) => Map k a -> String
3968-
showTree m
3969-
= showTreeWith showElem True False m
3970-
where
3971-
showElem k x = show k ++ ":=" ++ show x
3972-
3973-
3974-
{- | /O(n)/. The expression (@'showTreeWith' showelem hang wide map@) shows
3975-
the tree that implements the map. Elements are shown using the @showElem@ function. If @hang@ is
3976-
'True', a /hanging/ tree is shown otherwise a rotated tree is shown. If
3977-
@wide@ is 'True', an extra wide version is shown.
3978-
3979-
> Map> let t = fromDistinctAscList [(x,()) | x <- [1..5]]
3980-
> Map> putStrLn $ showTreeWith (\k x -> show (k,x)) True False t
3981-
> (4,())
3982-
> +--(2,())
3983-
> | +--(1,())
3984-
> | +--(3,())
3985-
> +--(5,())
3986-
>
3987-
> Map> putStrLn $ showTreeWith (\k x -> show (k,x)) True True t
3988-
> (4,())
3989-
> |
3990-
> +--(2,())
3991-
> | |
3992-
> | +--(1,())
3993-
> | |
3994-
> | +--(3,())
3995-
> |
3996-
> +--(5,())
3997-
>
3998-
> Map> putStrLn $ showTreeWith (\k x -> show (k,x)) False True t
3999-
> +--(5,())
4000-
> |
4001-
> (4,())
4002-
> |
4003-
> | +--(3,())
4004-
> | |
4005-
> +--(2,())
4006-
> |
4007-
> +--(1,())
4008-
4009-
-}
4010-
{-# DEPRECATED showTreeWith "This function is being removed from the public API." #-}
4011-
showTreeWith :: (k -> a -> String) -> Bool -> Bool -> Map k a -> String
4012-
showTreeWith showelem hang wide t
4013-
| hang = (showsTreeHang showelem wide [] t) ""
4014-
| otherwise = (showsTree showelem wide [] [] t) ""
4015-
4016-
showsTree :: (k -> a -> String) -> Bool -> [String] -> [String] -> Map k a -> ShowS
4017-
showsTree showelem wide lbars rbars t
4018-
= case t of
4019-
Tip -> showsBars lbars . showString "|\n"
4020-
Bin _ kx x Tip Tip
4021-
-> showsBars lbars . showString (showelem kx x) . showString "\n"
4022-
Bin _ kx x l r
4023-
-> showsTree showelem wide (withBar rbars) (withEmpty rbars) r .
4024-
showWide wide rbars .
4025-
showsBars lbars . showString (showelem kx x) . showString "\n" .
4026-
showWide wide lbars .
4027-
showsTree showelem wide (withEmpty lbars) (withBar lbars) l
4028-
4029-
showsTreeHang :: (k -> a -> String) -> Bool -> [String] -> Map k a -> ShowS
4030-
showsTreeHang showelem wide bars t
4031-
= case t of
4032-
Tip -> showsBars bars . showString "|\n"
4033-
Bin _ kx x Tip Tip
4034-
-> showsBars bars . showString (showelem kx x) . showString "\n"
4035-
Bin _ kx x l r
4036-
-> showsBars bars . showString (showelem kx x) . showString "\n" .
4037-
showWide wide bars .
4038-
showsTreeHang showelem wide (withBar bars) l .
4039-
showWide wide bars .
4040-
showsTreeHang showelem wide (withEmpty bars) r
4041-
4042-
showWide :: Bool -> [String] -> String -> String
4043-
showWide wide bars
4044-
| wide = showString (concat (reverse bars)) . showString "|\n"
4045-
| otherwise = id
4046-
4047-
showsBars :: [String] -> ShowS
4048-
showsBars bars
4049-
= case bars of
4050-
[] -> id
4051-
_ -> showString (concat (reverse (tail bars))) . showString node
4052-
4053-
node :: String
4054-
node = "+--"
4055-
4056-
withBar, withEmpty :: [String] -> [String]
4057-
withBar bars = "| ":bars
4058-
withEmpty bars = " ":bars
4059-
40603958
{--------------------------------------------------------------------
40613959
Typeable
40623960
--------------------------------------------------------------------}
40633961

40643962
INSTANCE_TYPEABLE2(Map)
40653963

4066-
{--------------------------------------------------------------------
4067-
Assertions
4068-
--------------------------------------------------------------------}
4069-
-- | /O(n)/. Test if the internal map structure is valid.
4070-
--
4071-
-- > valid (fromAscList [(3,"b"), (5,"a")]) == True
4072-
-- > valid (fromAscList [(5,"a"), (3,"b")]) == False
4073-
4074-
valid :: Ord k => Map k a -> Bool
4075-
valid t
4076-
= balanced t && ordered t && validsize t
4077-
4078-
ordered :: Ord a => Map a b -> Bool
4079-
ordered t
4080-
= bounded (const True) (const True) t
4081-
where
4082-
bounded lo hi t'
4083-
= case t' of
4084-
Tip -> True
4085-
Bin _ kx _ l r -> (lo kx) && (hi kx) && bounded lo (<kx) l && bounded (>kx) hi r
4086-
4087-
-- | Exported only for "Debug.QuickCheck"
4088-
balanced :: Map k a -> Bool
4089-
balanced t
4090-
= case t of
4091-
Tip -> True
4092-
Bin _ _ _ l r -> (size l + size r <= 1 || (size l <= delta*size r && size r <= delta*size l)) &&
4093-
balanced l && balanced r
4094-
4095-
validsize :: Map a b -> Bool
4096-
validsize t
4097-
= (realsize t == Just (size t))
4098-
where
4099-
realsize t'
4100-
= case t' of
4101-
Tip -> Just 0
4102-
Bin sz _ _ l r -> case (realsize l,realsize r) of
4103-
(Just n,Just m) | n+m+1 == sz -> Just sz
4104-
_ -> Nothing
4105-
41063964
{--------------------------------------------------------------------
41073965
Utilities
41083966
--------------------------------------------------------------------}

0 commit comments

Comments
 (0)