@@ -29,7 +29,7 @@ module Data.HashMap.Strict
29
29
-- * Strictness properties
30
30
-- $strictness
31
31
32
- HashMapW
32
+ HashMap
33
33
34
34
-- * Construction
35
35
, empty
@@ -117,7 +117,7 @@ import Data.HashMap.Unsafe (runST)
117
117
-- * Construction
118
118
119
119
-- | /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
121
121
singleton k ! v = HM. singleton k v
122
122
123
123
------------------------------------------------------------------------
@@ -126,7 +126,7 @@ singleton k !v = HM.singleton k v
126
126
-- | /O(log n)/ Associate the specified value with the specified
127
127
-- key in this map. If this map previously contained a mapping for
128
128
-- 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
130
130
insert k ! v = HM. insert k v
131
131
{-# INLINABLE insert #-}
132
132
@@ -137,11 +137,11 @@ insert k !v = HM.insert k v
137
137
--
138
138
-- > insertWith f k v map
139
139
-- > 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) =
143
143
let (diff, m0') = insertWithInternal f k0 v0 m0
144
- in HashMapW (diff + sz) m0'
144
+ in HashMap (diff + sz) m0'
145
145
{-# INLINABLE insertWith #-}
146
146
147
147
-- | /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
193
193
194
194
-- | In-place update version of insertWith
195
195
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) =
199
199
let (diff, m0') = unsafeInsertWithInternal f k0 v0 m0
200
- in HashMapW (diff + sz) m0'
200
+ in HashMap (diff + sz) m0'
201
201
{-# INLINABLE unsafeInsertWith #-}
202
202
203
203
-- | In-place update version of insertWith
@@ -247,8 +247,8 @@ unsafeInsertWithInternal f k0 v0 m0 = runST (go h0 k0 v0 0 m0)
247
247
248
248
-- | /O(log n)/ Adjust the value tied to a given key in this map only
249
249
-- 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)
252
252
where
253
253
h0 = hash k0
254
254
go ! _ ! _ ! _ Empty = Empty
@@ -277,7 +277,7 @@ adjust f k0 (HashMapW sz m0) = HashMapW sz (go h0 k0 0 m0)
277
277
-- | /O(log n)/ The expression (@'update' f k map@) updates the value @x@ at @k@,
278
278
-- (if it is in the map). If (f k x) is @'Nothing', the element is deleted.
279
279
-- 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
281
281
update f = alter (>>= f)
282
282
{-# INLINABLE update #-}
283
283
@@ -288,8 +288,8 @@ alter
288
288
:: (Eq k , Hashable k )
289
289
=> (Maybe v -> Maybe v )
290
290
-> k
291
- -> HashMapW k v
292
- -> HashMapW k v
291
+ -> HashMap k v
292
+ -> HashMap k v
293
293
alter f k m =
294
294
case f (HM. lookup k m) of
295
295
Nothing -> delete k m
@@ -301,8 +301,8 @@ alter f k m =
301
301
302
302
-- | /O(n+m)/ The union of two maps. If a key occurs in both maps,
303
303
-- 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
306
306
unionWith f = unionWithKey (const f)
307
307
{-# INLINE unionWith #-}
308
308
@@ -312,12 +312,12 @@ unionWith f = unionWithKey (const f)
312
312
unionWithKey
313
313
:: (Eq k , Hashable k )
314
314
=> (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 =
319
319
let (diff, m') = unionWithKeyInternal f m hw
320
- in HashMapW (diff + sz) m'
320
+ in HashMap (diff + sz) m'
321
321
{-# INLINE unionWithKey #-}
322
322
323
323
-- | /O(n+m)/ The union of two maps. If a key occurs in both maps,
@@ -326,9 +326,9 @@ unionWithKeyInternal
326
326
:: (Eq k , Hashable k )
327
327
=> (k -> v -> v -> v )
328
328
-> HashMapInner k v
329
- -> HashMapW k v
329
+ -> HashMap k v
330
330
-> (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
332
332
where
333
333
-- empty vs. anything
334
334
go ! _ ! sz t1 Empty = (sz, t1)
@@ -454,8 +454,8 @@ unionWithKeyInternal f hm1 (HashMapW siz hm2) = go 0 siz hm1 hm2
454
454
-- * Transformations
455
455
456
456
-- | /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)
459
459
where
460
460
go Empty = Empty
461
461
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)
466
466
{-# INLINE mapWithKey #-}
467
467
468
468
-- | /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
470
470
map f = mapWithKey (const f)
471
471
{-# INLINE map #-}
472
472
@@ -476,8 +476,8 @@ map f = mapWithKey (const f)
476
476
477
477
-- | /O(n)/ Transform this map by applying a function to every value
478
478
-- 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'
481
481
where onLeaf (Leaf h (L k v)) | Just v' <- f k v = Just (leaf h k v')
482
482
onLeaf _ = Nothing
483
483
@@ -489,7 +489,7 @@ mapMaybeWithKey f (HashMapW _ m) = HashMapW size' m'
489
489
490
490
-- | /O(n)/ Transform this map by applying a function to every value
491
491
-- 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
493
493
mapMaybe f = mapMaybeWithKey (const f)
494
494
{-# INLINE mapMaybe #-}
495
495
@@ -506,9 +506,9 @@ mapMaybe f = mapMaybeWithKey (const f)
506
506
differenceWith
507
507
:: (Eq k , Hashable k )
508
508
=> (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
512
512
differenceWith f a b = foldlWithKey' go empty a
513
513
where
514
514
go m k v = case HM. lookup k b of
@@ -519,8 +519,8 @@ differenceWith f a b = foldlWithKey' go empty a
519
519
-- | /O(n+m)/ Intersection of two maps. If a key occurs in both maps
520
520
-- the provided function is used to combine the values from the two
521
521
-- 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
524
524
intersectionWith f a b = foldlWithKey' go empty a
525
525
where
526
526
go m k v = case HM. lookup k b of
@@ -532,7 +532,7 @@ intersectionWith f a b = foldlWithKey' go empty a
532
532
-- the provided function is used to combine the values from the two
533
533
-- maps.
534
534
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
536
536
intersectionWithKey f a b = foldlWithKey' go empty a
537
537
where
538
538
go m k v = case HM. lookup k b of
@@ -546,7 +546,7 @@ intersectionWithKey f a b = foldlWithKey' go empty a
546
546
-- | /O(n*log n)/ Construct a map with the supplied mappings. If the
547
547
-- list contains duplicate mappings, the later mappings take
548
548
-- precedence.
549
- fromList :: (Eq k , Hashable k ) => [(k , v )] -> HashMapW k v
549
+ fromList :: (Eq k , Hashable k ) => [(k , v )] -> HashMap k v
550
550
fromList = L. foldl' (\ m (k, ! v) -> HM. unsafeInsert k v m) empty
551
551
{-# INLINABLE fromList #-}
552
552
@@ -563,7 +563,7 @@ fromList = L.foldl' (\ m (k, !v) -> HM.unsafeInsert k v m) empty
563
563
--
564
564
-- will group all values by their keys in a list 'xs :: [(k, v)]' and
565
565
-- 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
567
567
fromListWith f = L. foldl' (\ m (k, v) -> unsafeInsertWith f k v m) empty
568
568
{-# INLINE fromListWith #-}
569
569
0 commit comments