@@ -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
121121singleton 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
130130insert 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
195195unsafeInsertWith :: 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
281281update 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
293293alter 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
306306unionWith f = unionWithKey (const f)
307307{-# INLINE unionWith #-}
308308
@@ -312,12 +312,12 @@ unionWith f = unionWithKey (const f)
312312unionWithKey
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
470470map 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
493493mapMaybe f = mapMaybeWithKey (const f)
494494{-# INLINE mapMaybe #-}
495495
@@ -506,9 +506,9 @@ mapMaybe f = mapMaybeWithKey (const f)
506506differenceWith
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
512512differenceWith 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
524524intersectionWith 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.
534534intersectionWithKey :: (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
536536intersectionWithKey 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
550550fromList = 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
567567fromListWith f = L. foldl' (\ m (k, v) -> unsafeInsertWith f k v m) empty
568568{-# INLINE fromListWith #-}
569569
0 commit comments