Skip to content

Commit 5c6b2a2

Browse files
committed
Rename 'HashMapW' to 'HashMap'
This commit also updates the 'HashMap' Haddock comment, and reenables the correct 'Show' instance for 'HashMap', removing the 'deriving' one.
1 parent 743e037 commit 5c6b2a2

File tree

8 files changed

+203
-203
lines changed

8 files changed

+203
-203
lines changed

Data/HashMap/Base.hs

+116-116
Large diffs are not rendered by default.

Data/HashMap/Lazy.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module Data.HashMap.Lazy
2727
-- * Strictness properties
2828
-- $strictness
2929

30-
HashMapW
30+
HashMap
3131

3232
-- * Construction
3333
, empty

Data/HashMap/Strict.hs

+39-39
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module Data.HashMap.Strict
2929
-- * Strictness properties
3030
-- $strictness
3131

32-
HashMapW
32+
HashMap
3333

3434
-- * Construction
3535
, empty
@@ -117,7 +117,7 @@ import Data.HashMap.Unsafe (runST)
117117
-- * Construction
118118

119119
-- | /O(1)/ Construct a map with a single element.
120-
singleton :: (Hashable k) => k -> v -> HashMapW k v
120+
singleton :: (Hashable k) => k -> v -> HashMap k v
121121
singleton k !v = HM.singleton k v
122122

123123
------------------------------------------------------------------------
@@ -126,7 +126,7 @@ singleton k !v = HM.singleton k v
126126
-- | /O(log n)/ Associate the specified value with the specified
127127
-- key in this map. If this map previously contained a mapping for
128128
-- the key, the old value is replaced.
129-
insert :: (Eq k, Hashable k) => k -> v -> HashMapW k v -> HashMapW k v
129+
insert :: (Eq k, Hashable k) => k -> v -> HashMap k v -> HashMap k v
130130
insert k !v = HM.insert k v
131131
{-# INLINABLE insert #-}
132132

@@ -137,11 +137,11 @@ insert k !v = HM.insert k v
137137
--
138138
-- > insertWith f k v map
139139
-- > where f new old = new + old
140-
insertWith :: (Eq k, Hashable k) => (v -> v -> v) -> k -> v -> HashMapW k v
141-
-> HashMapW k v
142-
insertWith f k0 v0 (HashMapW sz m0) =
140+
insertWith :: (Eq k, Hashable k) => (v -> v -> v) -> k -> v -> HashMap k v
141+
-> HashMap k v
142+
insertWith f k0 v0 (HashMap sz m0) =
143143
let (diff, m0') = insertWithInternal f k0 v0 m0
144-
in HashMapW (diff + sz) m0'
144+
in HashMap (diff + sz) m0'
145145
{-# INLINABLE insertWith #-}
146146

147147
-- | /O(log n)/ Associate the value with the key in this map. If
@@ -193,11 +193,11 @@ insertWithInternal f k0 v0 m0 = go h0 k0 v0 0 m0
193193

194194
-- | In-place update version of insertWith
195195
unsafeInsertWith :: forall k v . (Eq k, Hashable k)
196-
=> (v -> v -> v) -> k -> v -> HashMapW k v
197-
-> HashMapW k v
198-
unsafeInsertWith f k0 v0 (HashMapW sz m0) =
196+
=> (v -> v -> v) -> k -> v -> HashMap k v
197+
-> HashMap k v
198+
unsafeInsertWith f k0 v0 (HashMap sz m0) =
199199
let (diff, m0') = unsafeInsertWithInternal f k0 v0 m0
200-
in HashMapW (diff + sz) m0'
200+
in HashMap (diff + sz) m0'
201201
{-# INLINABLE unsafeInsertWith #-}
202202

203203
-- | In-place update version of insertWith
@@ -247,8 +247,8 @@ unsafeInsertWithInternal f k0 v0 m0 = runST (go h0 k0 v0 0 m0)
247247

248248
-- | /O(log n)/ Adjust the value tied to a given key in this map only
249249
-- if it is present. Otherwise, leave the map alone.
250-
adjust :: (Eq k, Hashable k) => (v -> v) -> k -> HashMapW k v -> HashMapW k v
251-
adjust f k0 (HashMapW sz m0) = HashMapW sz (go h0 k0 0 m0)
250+
adjust :: (Eq k, Hashable k) => (v -> v) -> k -> HashMap k v -> HashMap k v
251+
adjust f k0 (HashMap sz m0) = HashMap sz (go h0 k0 0 m0)
252252
where
253253
h0 = hash k0
254254
go !_ !_ !_ Empty = Empty
@@ -277,7 +277,7 @@ adjust f k0 (HashMapW sz m0) = HashMapW sz (go h0 k0 0 m0)
277277
-- | /O(log n)/ The expression (@'update' f k map@) updates the value @x@ at @k@,
278278
-- (if it is in the map). If (f k x) is @'Nothing', the element is deleted.
279279
-- If it is (@'Just' y), the key k is bound to the new value y.
280-
update :: (Eq k, Hashable k) => (a -> Maybe a) -> k -> HashMapW k a -> HashMapW k a
280+
update :: (Eq k, Hashable k) => (a -> Maybe a) -> k -> HashMap k a -> HashMap k a
281281
update f = alter (>>= f)
282282
{-# INLINABLE update #-}
283283

@@ -288,8 +288,8 @@ alter
288288
:: (Eq k, Hashable k)
289289
=> (Maybe v -> Maybe v)
290290
-> k
291-
-> HashMapW k v
292-
-> HashMapW k v
291+
-> HashMap k v
292+
-> HashMap k v
293293
alter f k m =
294294
case f (HM.lookup k m) of
295295
Nothing -> delete k m
@@ -301,8 +301,8 @@ alter f k m =
301301

302302
-- | /O(n+m)/ The union of two maps. If a key occurs in both maps,
303303
-- the provided function (first argument) will be used to compute the result.
304-
unionWith :: (Eq k, Hashable k) => (v -> v -> v) -> HashMapW k v -> HashMapW k v
305-
-> HashMapW k v
304+
unionWith :: (Eq k, Hashable k) => (v -> v -> v) -> HashMap k v -> HashMap k v
305+
-> HashMap k v
306306
unionWith f = unionWithKey (const f)
307307
{-# INLINE unionWith #-}
308308

@@ -312,12 +312,12 @@ unionWith f = unionWithKey (const f)
312312
unionWithKey
313313
:: (Eq k, Hashable k)
314314
=> (k -> v -> v -> v)
315-
-> HashMapW k v
316-
-> HashMapW k v
317-
-> HashMapW k v
318-
unionWithKey f (HashMapW sz m) hw =
315+
-> HashMap k v
316+
-> HashMap k v
317+
-> HashMap k v
318+
unionWithKey f (HashMap sz m) hw =
319319
let (diff, m') = unionWithKeyInternal f m hw
320-
in HashMapW (diff + sz) m'
320+
in HashMap (diff + sz) m'
321321
{-# INLINE unionWithKey #-}
322322

323323
-- | /O(n+m)/ The union of two maps. If a key occurs in both maps,
@@ -326,9 +326,9 @@ unionWithKeyInternal
326326
:: (Eq k, Hashable k)
327327
=> (k -> v -> v -> v)
328328
-> HashMapInner k v
329-
-> HashMapW k v
329+
-> HashMap k v
330330
-> (Int, HashMapInner k v)
331-
unionWithKeyInternal f hm1 (HashMapW siz hm2) = go 0 siz hm1 hm2
331+
unionWithKeyInternal f hm1 (HashMap siz hm2) = go 0 siz hm1 hm2
332332
where
333333
-- empty vs. anything
334334
go !_ !sz t1 Empty = (sz, t1)
@@ -454,8 +454,8 @@ unionWithKeyInternal f hm1 (HashMapW siz hm2) = go 0 siz hm1 hm2
454454
-- * Transformations
455455

456456
-- | /O(n)/ Transform this map by applying a function to every value.
457-
mapWithKey :: (k -> v1 -> v2) -> HashMapW k v1 -> HashMapW k v2
458-
mapWithKey f (HashMapW sz m) = HashMapW sz (go m)
457+
mapWithKey :: (k -> v1 -> v2) -> HashMap k v1 -> HashMap k v2
458+
mapWithKey f (HashMap sz m) = HashMap sz (go m)
459459
where
460460
go Empty = Empty
461461
go (Leaf h (L k v)) = leaf h k (f k v)
@@ -466,7 +466,7 @@ mapWithKey f (HashMapW sz m) = HashMapW sz (go m)
466466
{-# INLINE mapWithKey #-}
467467

468468
-- | /O(n)/ Transform this map by applying a function to every value.
469-
map :: (v1 -> v2) -> HashMapW k v1 -> HashMapW k v2
469+
map :: (v1 -> v2) -> HashMap k v1 -> HashMap k v2
470470
map f = mapWithKey (const f)
471471
{-# INLINE map #-}
472472

@@ -476,8 +476,8 @@ map f = mapWithKey (const f)
476476

477477
-- | /O(n)/ Transform this map by applying a function to every value
478478
-- and retaining only some of them.
479-
mapMaybeWithKey :: (k -> v1 -> Maybe v2) -> HashMapW k v1 -> HashMapW k v2
480-
mapMaybeWithKey f (HashMapW _ m) = HashMapW size' m'
479+
mapMaybeWithKey :: (k -> v1 -> Maybe v2) -> HashMap k v1 -> HashMap k v2
480+
mapMaybeWithKey f (HashMap _ m) = HashMap size' m'
481481
where onLeaf (Leaf h (L k v)) | Just v' <- f k v = Just (leaf h k v')
482482
onLeaf _ = Nothing
483483

@@ -489,7 +489,7 @@ mapMaybeWithKey f (HashMapW _ m) = HashMapW size' m'
489489

490490
-- | /O(n)/ Transform this map by applying a function to every value
491491
-- and retaining only some of them.
492-
mapMaybe :: (v1 -> Maybe v2) -> HashMapW k v1 -> HashMapW k v2
492+
mapMaybe :: (v1 -> Maybe v2) -> HashMap k v1 -> HashMap k v2
493493
mapMaybe f = mapMaybeWithKey (const f)
494494
{-# INLINE mapMaybe #-}
495495

@@ -506,9 +506,9 @@ mapMaybe f = mapMaybeWithKey (const f)
506506
differenceWith
507507
:: (Eq k, Hashable k)
508508
=> (v -> w -> Maybe v)
509-
-> HashMapW k v
510-
-> HashMapW k w
511-
-> HashMapW k v
509+
-> HashMap k v
510+
-> HashMap k w
511+
-> HashMap k v
512512
differenceWith f a b = foldlWithKey' go empty a
513513
where
514514
go m k v = case HM.lookup k b of
@@ -519,8 +519,8 @@ differenceWith f a b = foldlWithKey' go empty a
519519
-- | /O(n+m)/ Intersection of two maps. If a key occurs in both maps
520520
-- the provided function is used to combine the values from the two
521521
-- maps.
522-
intersectionWith :: (Eq k, Hashable k) => (v1 -> v2 -> v3) -> HashMapW k v1
523-
-> HashMapW k v2 -> HashMapW k v3
522+
intersectionWith :: (Eq k, Hashable k) => (v1 -> v2 -> v3) -> HashMap k v1
523+
-> HashMap k v2 -> HashMap k v3
524524
intersectionWith f a b = foldlWithKey' go empty a
525525
where
526526
go m k v = case HM.lookup k b of
@@ -532,7 +532,7 @@ intersectionWith f a b = foldlWithKey' go empty a
532532
-- the provided function is used to combine the values from the two
533533
-- maps.
534534
intersectionWithKey :: (Eq k, Hashable k) => (k -> v1 -> v2 -> v3)
535-
-> HashMapW k v1 -> HashMapW k v2 -> HashMapW k v3
535+
-> HashMap k v1 -> HashMap k v2 -> HashMap k v3
536536
intersectionWithKey f a b = foldlWithKey' go empty a
537537
where
538538
go m k v = case HM.lookup k b of
@@ -546,7 +546,7 @@ intersectionWithKey f a b = foldlWithKey' go empty a
546546
-- | /O(n*log n)/ Construct a map with the supplied mappings. If the
547547
-- list contains duplicate mappings, the later mappings take
548548
-- precedence.
549-
fromList :: (Eq k, Hashable k) => [(k, v)] -> HashMapW k v
549+
fromList :: (Eq k, Hashable k) => [(k, v)] -> HashMap k v
550550
fromList = L.foldl' (\ m (k, !v) -> HM.unsafeInsert k v m) empty
551551
{-# INLINABLE fromList #-}
552552

@@ -563,7 +563,7 @@ fromList = L.foldl' (\ m (k, !v) -> HM.unsafeInsert k v m) empty
563563
--
564564
-- will group all values by their keys in a list 'xs :: [(k, v)]' and
565565
-- return a 'HashMap k [v]'.
566-
fromListWith :: (Eq k, Hashable k) => (v -> v -> v) -> [(k, v)] -> HashMapW k v
566+
fromListWith :: (Eq k, Hashable k) => (v -> v -> v) -> [(k, v)] -> HashMap k v
567567
fromListWith f = L.foldl' (\ m (k, v) -> unsafeInsertWith f k v m) empty
568568
{-# INLINE fromListWith #-}
569569

Data/HashSet.hs

+7-7
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ module Data.HashSet
6767
, toList
6868
, fromList
6969

70-
-- * HashMapWs
70+
-- * HashMaps
7171
, toMap
7272
, fromMap
7373
) where
7474

7575
import Control.DeepSeq (NFData(..))
7676
import Data.Data hiding (Typeable)
77-
import Data.HashMap.Base (HashMapW, foldrWithKey, equalKeys)
77+
import Data.HashMap.Base (HashMap, foldrWithKey, equalKeys)
7878
import Data.Hashable (Hashable(hashWithSalt))
7979
#if __GLASGOW_HASKELL__ >= 711
8080
import Data.Semigroup (Semigroup(..), Monoid(..))
@@ -103,7 +103,7 @@ import qualified Data.Hashable.Lifted as H
103103

104104
-- | A set of values. A set cannot contain duplicate values.
105105
newtype HashSet a = HashSet {
106-
asMap :: HashMapW a ()
106+
asMap :: HashMap a ()
107107
} deriving (Typeable)
108108

109109
#if __GLASGOW_HASKELL__ >= 708
@@ -202,12 +202,12 @@ singleton :: Hashable a => a -> HashSet a
202202
singleton a = HashSet (H.singleton a ())
203203
{-# INLINABLE singleton #-}
204204

205-
-- | /O(1)/ Convert to the equivalent 'HashMapW'.
206-
toMap :: HashSet a -> HashMapW a ()
205+
-- | /O(1)/ Convert to the equivalent 'HashMap'.
206+
toMap :: HashSet a -> HashMap a ()
207207
toMap = asMap
208208

209-
-- | /O(1)/ Convert from the equivalent 'HashMapW'.
210-
fromMap :: HashMapW a () -> HashSet a
209+
-- | /O(1)/ Convert from the equivalent 'HashMap'.
210+
fromMap :: HashMap a () -> HashSet a
211211
fromMap = HashSet
212212

213213
-- | /O(n+m)/ Construct a set containing all elements from both sets.

benchmarks/Benchmarks.hs

+25-25
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ data Env = Env {
5555
elemsDupBS :: ![(BS.ByteString, Int)],
5656
elemsDupI :: ![(Int, Int)],
5757

58-
hm :: !(HM.HashMapW String Int),
59-
hmbs :: !(HM.HashMapW BS.ByteString Int),
60-
hmi :: !(HM.HashMapW Int Int),
61-
hmi2 :: !(HM.HashMapW Int Int),
58+
hm :: !(HM.HashMap String Int),
59+
hmbs :: !(HM.HashMap BS.ByteString Int),
60+
hmi :: !(HM.HashMap Int Int),
61+
hmi2 :: !(HM.HashMap Int Int),
6262
m :: !(M.Map String Int),
6363
mbs :: !(M.Map BS.ByteString Int),
6464
im :: !(IM.IntMap Int),
@@ -195,7 +195,7 @@ main = do
195195
]
196196

197197
, env setupEnv $ \ ~(Env{..}) ->
198-
bgroup "HashMapW"
198+
bgroup "HashMap"
199199
[ -- * Basic interface
200200
bgroup "lookup"
201201
[ bench "String" $ whnf (lookup keys) hm
@@ -283,32 +283,32 @@ main = do
283283
]
284284

285285
------------------------------------------------------------------------
286-
-- * HashMapW
286+
-- * HashMap
287287

288-
lookup :: (Eq k, Hashable k) => [k] -> HM.HashMapW k Int -> Int
288+
lookup :: (Eq k, Hashable k) => [k] -> HM.HashMap k Int -> Int
289289
lookup xs m = foldl' (\z k -> fromMaybe z (HM.lookup k m)) 0 xs
290-
{-# SPECIALIZE lookup :: [Int] -> HM.HashMapW Int Int -> Int #-}
291-
{-# SPECIALIZE lookup :: [String] -> HM.HashMapW String Int -> Int #-}
292-
{-# SPECIALIZE lookup :: [BS.ByteString] -> HM.HashMapW BS.ByteString Int
290+
{-# SPECIALIZE lookup :: [Int] -> HM.HashMap Int Int -> Int #-}
291+
{-# SPECIALIZE lookup :: [String] -> HM.HashMap String Int -> Int #-}
292+
{-# SPECIALIZE lookup :: [BS.ByteString] -> HM.HashMap BS.ByteString Int
293293
-> Int #-}
294294

295-
insert :: (Eq k, Hashable k) => [(k, Int)] -> HM.HashMapW k Int
296-
-> HM.HashMapW k Int
295+
insert :: (Eq k, Hashable k) => [(k, Int)] -> HM.HashMap k Int
296+
-> HM.HashMap k Int
297297
insert xs m0 = foldl' (\m (k, v) -> HM.insert k v m) m0 xs
298-
{-# SPECIALIZE insert :: [(Int, Int)] -> HM.HashMapW Int Int
299-
-> HM.HashMapW Int Int #-}
300-
{-# SPECIALIZE insert :: [(String, Int)] -> HM.HashMapW String Int
301-
-> HM.HashMapW String Int #-}
302-
{-# SPECIALIZE insert :: [(BS.ByteString, Int)] -> HM.HashMapW BS.ByteString Int
303-
-> HM.HashMapW BS.ByteString Int #-}
304-
305-
delete :: (Eq k, Hashable k) => [k] -> HM.HashMapW k Int -> HM.HashMapW k Int
298+
{-# SPECIALIZE insert :: [(Int, Int)] -> HM.HashMap Int Int
299+
-> HM.HashMap Int Int #-}
300+
{-# SPECIALIZE insert :: [(String, Int)] -> HM.HashMap String Int
301+
-> HM.HashMap String Int #-}
302+
{-# SPECIALIZE insert :: [(BS.ByteString, Int)] -> HM.HashMap BS.ByteString Int
303+
-> HM.HashMap BS.ByteString Int #-}
304+
305+
delete :: (Eq k, Hashable k) => [k] -> HM.HashMap k Int -> HM.HashMap k Int
306306
delete xs m0 = foldl' (\m k -> HM.delete k m) m0 xs
307-
{-# SPECIALIZE delete :: [Int] -> HM.HashMapW Int Int -> HM.HashMapW Int Int #-}
308-
{-# SPECIALIZE delete :: [String] -> HM.HashMapW String Int
309-
-> HM.HashMapW String Int #-}
310-
{-# SPECIALIZE delete :: [BS.ByteString] -> HM.HashMapW BS.ByteString Int
311-
-> HM.HashMapW BS.ByteString Int #-}
307+
{-# SPECIALIZE delete :: [Int] -> HM.HashMap Int Int -> HM.HashMap Int Int #-}
308+
{-# SPECIALIZE delete :: [String] -> HM.HashMap String Int
309+
-> HM.HashMap String Int #-}
310+
{-# SPECIALIZE delete :: [BS.ByteString] -> HM.HashMap BS.ByteString Int
311+
-> HM.HashMap BS.ByteString Int #-}
312312

313313
------------------------------------------------------------------------
314314
-- * Map

tests/HashMapProperties.hs

+3-3
Original file line numberDiff line numberDiff line change
@@ -364,15 +364,15 @@ type Model k v = M.Map k v
364364
-- one operating on a 'Model'.
365365
eq :: (Eq a, Eq k, Hashable k, Ord k)
366366
=> (Model k v -> a) -- ^ Function that modifies a 'Model'
367-
-> (HM.HashMapW k v -> a) -- ^ Function that modified a 'HashMap' in the same
367+
-> (HM.HashMap k v -> a) -- ^ Function that modified a 'HashMap' in the same
368368
-- way
369369
-> [(k, v)] -- ^ Initial content of the 'HashMap' and 'Model'
370370
-> Bool -- ^ True if the functions are equivalent
371371
eq f g xs = g (HM.fromList xs) == f (M.fromList xs)
372372

373373
eq_ :: (Eq k, Eq v, Hashable k, Ord k)
374374
=> (Model k v -> Model k v) -- ^ Function that modifies a 'Model'
375-
-> (HM.HashMapW k v -> HM.HashMapW k v) -- ^ Function that modified a
375+
-> (HM.HashMap k v -> HM.HashMap k v) -- ^ Function that modified a
376376
-- 'HashMap' in the same way
377377
-> [(k, v)] -- ^ Initial content of the 'HashMap'
378378
-- and 'Model'
@@ -392,5 +392,5 @@ main = defaultMain tests
392392
sortByKey :: Ord k => [(k, v)] -> [(k, v)]
393393
sortByKey = L.sortBy (compare `on` fst)
394394

395-
toAscList :: Ord k => HM.HashMapW k v -> [(k, v)]
395+
toAscList :: Ord k => HM.HashMap k v -> [(k, v)]
396396
toAscList = L.sortBy (compare `on` fst) . HM.toList

tests/Regressions.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ propEqAfterDelete (Keys keys) =
6868
k = head keys
6969
in HM.delete k keyMap == mapFromKeys (delete k keys)
7070

71-
mapFromKeys :: [Int] -> HM.HashMapW Int ()
71+
mapFromKeys :: [Int] -> HM.HashMap Int ()
7272
mapFromKeys keys = HM.fromList (zip keys (repeat ()))
7373

7474
------------------------------------------------------------------------

0 commit comments

Comments
 (0)