38
38
-- especially when key comparison is expensive, as in the case of
39
39
-- strings.
40
40
--
41
- -- Many operations have a average-case complexity of /O( log n)/ . The
41
+ -- Many operations have a average-case complexity of \(O(\ log n)\) . The
42
42
-- implementation uses a large base (i.e. 32) so in practice these
43
43
-- operations are constant time.
44
44
module Data.HashMap.Internal.Strict
@@ -164,21 +164,21 @@ values are exempted.
164
164
------------------------------------------------------------------------
165
165
-- * Construction
166
166
167
- -- | / O(1)/ Construct a map with a single element.
167
+ -- | \( O(1)\) Construct a map with a single element.
168
168
singleton :: (Hashable k ) => k -> v -> HashMap k v
169
169
singleton k ! v = HM. singleton k v
170
170
171
171
------------------------------------------------------------------------
172
172
-- * Basic interface
173
173
174
- -- | /O( log n)/ Associate the specified value with the specified
174
+ -- | \(O(\ log n)\) Associate the specified value with the specified
175
175
-- key in this map. If this map previously contained a mapping for
176
176
-- the key, the old value is replaced.
177
177
insert :: (Eq k , Hashable k ) => k -> v -> HashMap k v -> HashMap k v
178
178
insert k ! v = HM. insert k v
179
179
{-# INLINABLE insert #-}
180
180
181
- -- | /O( log n)/ Associate the value with the key in this map. If
181
+ -- | \(O(\ log n)\) Associate the value with the key in this map. If
182
182
-- this map previously contained a mapping for the key, the old value
183
183
-- is replaced by the result of applying the given function to the new
184
184
-- and old value. Example:
@@ -259,7 +259,7 @@ unsafeInsertWithKey f k0 v0 m0 = runST (go h0 k0 v0 0 m0)
259
259
| otherwise = go h k x s $ BitmapIndexed (mask hy s) (A. singleton t)
260
260
{-# INLINABLE unsafeInsertWithKey #-}
261
261
262
- -- | /O( log n)/ Adjust the value tied to a given key in this map only
262
+ -- | \(O(\ log n)\) Adjust the value tied to a given key in this map only
263
263
-- if it is present. Otherwise, leave the map alone.
264
264
adjust :: (Eq k , Hashable k ) => (v -> v ) -> k -> HashMap k v -> HashMap k v
265
265
adjust f k0 m0 = go h0 k0 0 m0
@@ -288,14 +288,14 @@ adjust f k0 m0 = go h0 k0 0 m0
288
288
| otherwise = t
289
289
{-# INLINABLE adjust #-}
290
290
291
- -- | /O( log n)/ The expression @('update' f k map)@ updates the value @x@ at @k@
291
+ -- | \(O(\ log n)\) The expression @('update' f k map)@ updates the value @x@ at @k@
292
292
-- (if it is in the map). If @(f x)@ is 'Nothing', the element is deleted.
293
293
-- If it is @('Just' y)@, the key @k@ is bound to the new value @y@.
294
294
update :: (Eq k , Hashable k ) => (a -> Maybe a ) -> k -> HashMap k a -> HashMap k a
295
295
update f = alter (>>= f)
296
296
{-# INLINABLE update #-}
297
297
298
- -- | /O( log n)/ The expression @('alter' f k map)@ alters the value @x@ at @k@, or
298
+ -- | \(O(\ log n)\) The expression @('alter' f k map)@ alters the value @x@ at @k@, or
299
299
-- absence thereof.
300
300
--
301
301
-- 'alter' can be used to insert, delete, or update a value in a map. In short:
@@ -310,7 +310,7 @@ alter f k m =
310
310
Just v -> insert k v m
311
311
{-# INLINABLE alter #-}
312
312
313
- -- | /O( log n)/ The expression (@'alterF' f k map@) alters the value @x@ at
313
+ -- | \(O(\ log n)\) The expression (@'alterF' f k map@) alters the value @x@ at
314
314
-- @k@, or absence thereof.
315
315
--
316
316
-- 'alterF' can be used to insert, delete, or update a value in a map.
@@ -436,14 +436,14 @@ alterFEager f !k !m = (<$> f mv) $ \fres ->
436
436
------------------------------------------------------------------------
437
437
-- * Combine
438
438
439
- -- | / O(n+m)/ The union of two maps. If a key occurs in both maps,
439
+ -- | \( O(n+m)\) The union of two maps. If a key occurs in both maps,
440
440
-- the provided function (first argument) will be used to compute the result.
441
441
unionWith :: (Eq k , Hashable k ) => (v -> v -> v ) -> HashMap k v -> HashMap k v
442
442
-> HashMap k v
443
443
unionWith f = unionWithKey (const f)
444
444
{-# INLINE unionWith #-}
445
445
446
- -- | / O(n+m)/ The union of two maps. If a key occurs in both maps,
446
+ -- | \( O(n+m)\) The union of two maps. If a key occurs in both maps,
447
447
-- the provided function (first argument) will be used to compute the result.
448
448
unionWithKey :: (Eq k , Hashable k ) => (k -> v -> v -> v ) -> HashMap k v -> HashMap k v
449
449
-> HashMap k v
@@ -532,7 +532,7 @@ unionWithKey f = go 0
532
532
------------------------------------------------------------------------
533
533
-- * Transformations
534
534
535
- -- | / O(n)/ Transform this map by applying a function to every value.
535
+ -- | \( O(n)\) Transform this map by applying a function to every value.
536
536
mapWithKey :: (k -> v1 -> v2 ) -> HashMap k v1 -> HashMap k v2
537
537
mapWithKey f = go
538
538
where
@@ -544,7 +544,7 @@ mapWithKey f = go
544
544
Collision h $ A. map' (\ (L k v) -> let ! v' = f k v in L k v') ary
545
545
{-# INLINE mapWithKey #-}
546
546
547
- -- | / O(n)/ Transform this map by applying a function to every value.
547
+ -- | \( O(n)\) Transform this map by applying a function to every value.
548
548
map :: (v1 -> v2 ) -> HashMap k v1 -> HashMap k v2
549
549
map f = mapWithKey (const f)
550
550
{-# INLINE map #-}
@@ -553,7 +553,7 @@ map f = mapWithKey (const f)
553
553
------------------------------------------------------------------------
554
554
-- * Filter
555
555
556
- -- | / O(n)/ Transform this map by applying a function to every value
556
+ -- | \( O(n)\) Transform this map by applying a function to every value
557
557
-- and retaining only some of them.
558
558
mapMaybeWithKey :: (k -> v1 -> Maybe v2 ) -> HashMap k v1 -> HashMap k v2
559
559
mapMaybeWithKey f = HM. filterMapAux onLeaf onColl
@@ -564,13 +564,13 @@ mapMaybeWithKey f = HM.filterMapAux onLeaf onColl
564
564
| otherwise = Nothing
565
565
{-# INLINE mapMaybeWithKey #-}
566
566
567
- -- | / O(n)/ Transform this map by applying a function to every value
567
+ -- | \( O(n)\) Transform this map by applying a function to every value
568
568
-- and retaining only some of them.
569
569
mapMaybe :: (v1 -> Maybe v2 ) -> HashMap k v1 -> HashMap k v2
570
570
mapMaybe f = mapMaybeWithKey (const f)
571
571
{-# INLINE mapMaybe #-}
572
572
573
- -- | / O(n)/ Perform an 'Applicative' action for each key-value pair
573
+ -- | \( O(n)\) Perform an 'Applicative' action for each key-value pair
574
574
-- in a 'HashMap' and produce a 'HashMap' of all the results. Each 'HashMap'
575
575
-- will be strict in all its values.
576
576
--
@@ -599,7 +599,7 @@ traverseWithKey f = go
599
599
------------------------------------------------------------------------
600
600
-- * Difference and intersection
601
601
602
- -- | / O(n* log m)/ Difference with a combining function. When two equal keys are
602
+ -- | \( O(n \ log m)\) Difference with a combining function. When two equal keys are
603
603
-- encountered, the combining function is applied to the values of these keys.
604
604
-- If it returns 'Nothing', the element is discarded (proper set difference). If
605
605
-- it returns (@'Just' y@), the element is updated with a new value @y@.
@@ -611,7 +611,7 @@ differenceWith f a b = HM.foldlWithKey' go HM.empty a
611
611
Just w -> maybe m (\ ! y -> HM. unsafeInsert k y m) (f v w)
612
612
{-# INLINABLE differenceWith #-}
613
613
614
- -- | / O(n+m)/ Intersection of two maps. If a key occurs in both maps
614
+ -- | \( O(n+m)\) Intersection of two maps. If a key occurs in both maps
615
615
-- the provided function is used to combine the values from the two
616
616
-- maps.
617
617
intersectionWith :: (Eq k , Hashable k ) => (v1 -> v2 -> v3 ) -> HashMap k v1
@@ -623,7 +623,7 @@ intersectionWith f a b = HM.foldlWithKey' go HM.empty a
623
623
_ -> m
624
624
{-# INLINABLE intersectionWith #-}
625
625
626
- -- | / O(n+m)/ Intersection of two maps. If a key occurs in both maps
626
+ -- | \( O(n+m)\) Intersection of two maps. If a key occurs in both maps
627
627
-- the provided function is used to combine the values from the two
628
628
-- maps.
629
629
intersectionWithKey :: (Eq k , Hashable k ) => (k -> v1 -> v2 -> v3 )
@@ -638,14 +638,14 @@ intersectionWithKey f a b = HM.foldlWithKey' go HM.empty a
638
638
------------------------------------------------------------------------
639
639
-- ** Lists
640
640
641
- -- | / O(n* log n)/ Construct a map with the supplied mappings. If the
641
+ -- | \( O(n \ log n)\) Construct a map with the supplied mappings. If the
642
642
-- list contains duplicate mappings, the later mappings take
643
643
-- precedence.
644
644
fromList :: (Eq k , Hashable k ) => [(k , v )] -> HashMap k v
645
645
fromList = List. foldl' (\ m (k, ! v) -> HM. unsafeInsert k v m) HM. empty
646
646
{-# INLINABLE fromList #-}
647
647
648
- -- | / O(n* log n)/ Construct a map from a list of elements. Uses
648
+ -- | \( O(n \ log n)\) Construct a map from a list of elements. Uses
649
649
-- the provided function @f@ to merge duplicate entries with
650
650
-- @(f newVal oldVal)@.
651
651
--
@@ -679,7 +679,7 @@ fromListWith :: (Eq k, Hashable k) => (v -> v -> v) -> [(k, v)] -> HashMap k v
679
679
fromListWith f = List. foldl' (\ m (k, v) -> unsafeInsertWith f k v m) HM. empty
680
680
{-# INLINE fromListWith #-}
681
681
682
- -- | / O(n* log n)/ Construct a map from a list of elements. Uses
682
+ -- | \( O(n \ log n)\) Construct a map from a list of elements. Uses
683
683
-- the provided function to merge duplicate entries.
684
684
--
685
685
-- === Examples
0 commit comments