3838-- especially when key comparison is expensive, as in the case of
3939-- strings.
4040--
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
4242-- implementation uses a large base (i.e. 32) so in practice these
4343-- operations are constant time.
4444module Data.HashMap.Internal.Strict
@@ -164,21 +164,21 @@ values are exempted.
164164------------------------------------------------------------------------
165165-- * Construction
166166
167- -- | / O(1)/ Construct a map with a single element.
167+ -- | \( O(1)\) Construct a map with a single element.
168168singleton :: (Hashable k ) => k -> v -> HashMap k v
169169singleton k ! v = HM. singleton k v
170170
171171------------------------------------------------------------------------
172172-- * Basic interface
173173
174- -- | /O( log n)/ Associate the specified value with the specified
174+ -- | \(O(\ log n)\) Associate the specified value with the specified
175175-- key in this map. If this map previously contained a mapping for
176176-- the key, the old value is replaced.
177177insert :: (Eq k , Hashable k ) => k -> v -> HashMap k v -> HashMap k v
178178insert k ! v = HM. insert k v
179179{-# INLINABLE insert #-}
180180
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
182182-- this map previously contained a mapping for the key, the old value
183183-- is replaced by the result of applying the given function to the new
184184-- and old value. Example:
@@ -259,7 +259,7 @@ unsafeInsertWithKey f k0 v0 m0 = runST (go h0 k0 v0 0 m0)
259259 | otherwise = go h k x s $ BitmapIndexed (mask hy s) (A. singleton t)
260260{-# INLINABLE unsafeInsertWithKey #-}
261261
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
263263-- if it is present. Otherwise, leave the map alone.
264264adjust :: (Eq k , Hashable k ) => (v -> v ) -> k -> HashMap k v -> HashMap k v
265265adjust f k0 m0 = go h0 k0 0 m0
@@ -288,14 +288,14 @@ adjust f k0 m0 = go h0 k0 0 m0
288288 | otherwise = t
289289{-# INLINABLE adjust #-}
290290
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@
292292-- (if it is in the map). If @(f x)@ is 'Nothing', the element is deleted.
293293-- If it is @('Just' y)@, the key @k@ is bound to the new value @y@.
294294update :: (Eq k , Hashable k ) => (a -> Maybe a ) -> k -> HashMap k a -> HashMap k a
295295update f = alter (>>= f)
296296{-# INLINABLE update #-}
297297
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
299299-- absence thereof.
300300--
301301-- 'alter' can be used to insert, delete, or update a value in a map. In short:
@@ -310,7 +310,7 @@ alter f k m =
310310 Just v -> insert k v m
311311{-# INLINABLE alter #-}
312312
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
314314-- @k@, or absence thereof.
315315--
316316-- '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 ->
436436------------------------------------------------------------------------
437437-- * Combine
438438
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,
440440-- the provided function (first argument) will be used to compute the result.
441441unionWith :: (Eq k , Hashable k ) => (v -> v -> v ) -> HashMap k v -> HashMap k v
442442 -> HashMap k v
443443unionWith f = unionWithKey (const f)
444444{-# INLINE unionWith #-}
445445
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,
447447-- the provided function (first argument) will be used to compute the result.
448448unionWithKey :: (Eq k , Hashable k ) => (k -> v -> v -> v ) -> HashMap k v -> HashMap k v
449449 -> HashMap k v
@@ -532,7 +532,7 @@ unionWithKey f = go 0
532532------------------------------------------------------------------------
533533-- * Transformations
534534
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.
536536mapWithKey :: (k -> v1 -> v2 ) -> HashMap k v1 -> HashMap k v2
537537mapWithKey f = go
538538 where
@@ -544,7 +544,7 @@ mapWithKey f = go
544544 Collision h $ A. map' (\ (L k v) -> let ! v' = f k v in L k v') ary
545545{-# INLINE mapWithKey #-}
546546
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.
548548map :: (v1 -> v2 ) -> HashMap k v1 -> HashMap k v2
549549map f = mapWithKey (const f)
550550{-# INLINE map #-}
@@ -553,7 +553,7 @@ map f = mapWithKey (const f)
553553------------------------------------------------------------------------
554554-- * Filter
555555
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
557557-- and retaining only some of them.
558558mapMaybeWithKey :: (k -> v1 -> Maybe v2 ) -> HashMap k v1 -> HashMap k v2
559559mapMaybeWithKey f = HM. filterMapAux onLeaf onColl
@@ -564,13 +564,13 @@ mapMaybeWithKey f = HM.filterMapAux onLeaf onColl
564564 | otherwise = Nothing
565565{-# INLINE mapMaybeWithKey #-}
566566
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
568568-- and retaining only some of them.
569569mapMaybe :: (v1 -> Maybe v2 ) -> HashMap k v1 -> HashMap k v2
570570mapMaybe f = mapMaybeWithKey (const f)
571571{-# INLINE mapMaybe #-}
572572
573- -- | / O(n)/ Perform an 'Applicative' action for each key-value pair
573+ -- | \( O(n)\) Perform an 'Applicative' action for each key-value pair
574574-- in a 'HashMap' and produce a 'HashMap' of all the results. Each 'HashMap'
575575-- will be strict in all its values.
576576--
@@ -599,7 +599,7 @@ traverseWithKey f = go
599599------------------------------------------------------------------------
600600-- * Difference and intersection
601601
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
603603-- encountered, the combining function is applied to the values of these keys.
604604-- If it returns 'Nothing', the element is discarded (proper set difference). If
605605-- 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
611611 Just w -> maybe m (\ ! y -> HM. unsafeInsert k y m) (f v w)
612612{-# INLINABLE differenceWith #-}
613613
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
615615-- the provided function is used to combine the values from the two
616616-- maps.
617617intersectionWith :: (Eq k , Hashable k ) => (v1 -> v2 -> v3 ) -> HashMap k v1
@@ -623,7 +623,7 @@ intersectionWith f a b = HM.foldlWithKey' go HM.empty a
623623 _ -> m
624624{-# INLINABLE intersectionWith #-}
625625
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
627627-- the provided function is used to combine the values from the two
628628-- maps.
629629intersectionWithKey :: (Eq k , Hashable k ) => (k -> v1 -> v2 -> v3 )
@@ -638,14 +638,14 @@ intersectionWithKey f a b = HM.foldlWithKey' go HM.empty a
638638------------------------------------------------------------------------
639639-- ** Lists
640640
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
642642-- list contains duplicate mappings, the later mappings take
643643-- precedence.
644644fromList :: (Eq k , Hashable k ) => [(k , v )] -> HashMap k v
645645fromList = List. foldl' (\ m (k, ! v) -> HM. unsafeInsert k v m) HM. empty
646646{-# INLINABLE fromList #-}
647647
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
649649-- the provided function @f@ to merge duplicate entries with
650650-- @(f newVal oldVal)@.
651651--
@@ -679,7 +679,7 @@ fromListWith :: (Eq k, Hashable k) => (v -> v -> v) -> [(k, v)] -> HashMap k v
679679fromListWith f = List. foldl' (\ m (k, v) -> unsafeInsertWith f k v m) HM. empty
680680{-# INLINE fromListWith #-}
681681
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
683683-- the provided function to merge duplicate entries.
684684--
685685-- === Examples
0 commit comments