Skip to content

Commit

Permalink
Fix some complexities in IntMap.Strict (#1114)
Browse files Browse the repository at this point in the history
  • Loading branch information
meooow25 authored Feb 24, 2025
1 parent 369fb4b commit 02b56b7
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions containers/src/Data/IntMap/Strict/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ alter f !k t =
Just !x -> Tip k x
Nothing -> Nil

-- | \(O(\log n)\). The expression (@'alterF' f k map@) alters the value @x@ at
-- | \(O(\min(n,W))\). The expression (@'alterF' f k map@) alters the value @x@ at
-- @k@, or absence thereof. 'alterF' can be used to inspect, insert, delete,
-- or update a value in an 'IntMap'. In short : @'lookup' k \<$\> 'alterF' f k m = f
-- ('lookup' k m)@.
Expand Down Expand Up @@ -765,7 +765,7 @@ mergeWithKey f g1 g2 = mergeWithKey' bin combine g1 g2
Min\/Max
--------------------------------------------------------------------}

-- | \(O(\log n)\). Update the value at the minimal key.
-- | \(O(\min(n,W))\). Update the value at the minimal key.
--
-- > updateMinWithKey (\ k a -> Just ((show k) ++ ":" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3,"3:b"), (5,"a")]
-- > updateMinWithKey (\ _ _ -> Nothing) (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
Expand All @@ -781,7 +781,7 @@ updateMinWithKey f t =
Nothing -> Nil
go _ Nil = Nil

-- | \(O(\log n)\). Update the value at the maximal key.
-- | \(O(\min(n,W))\). Update the value at the maximal key.
--
-- > updateMaxWithKey (\ k a -> Just ((show k) ++ ":" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3,"b"), (5,"5:a")]
-- > updateMaxWithKey (\ _ _ -> Nothing) (fromList [(5,"a"), (3,"b")]) == singleton 3 "b"
Expand All @@ -797,15 +797,15 @@ updateMaxWithKey f t =
Nothing -> Nil
go _ Nil = Nil

-- | \(O(\log n)\). Update the value at the maximal key.
-- | \(O(\min(n,W))\). Update the value at the maximal key.
--
-- > updateMax (\ a -> Just ("X" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "Xa")]
-- > updateMax (\ _ -> Nothing) (fromList [(5,"a"), (3,"b")]) == singleton 3 "b"

updateMax :: (a -> Maybe a) -> IntMap a -> IntMap a
updateMax f = updateMaxWithKey (const f)

-- | \(O(\log n)\). Update the value at the minimal key.
-- | \(O(\min(n,W))\). Update the value at the minimal key.
--
-- > updateMin (\ a -> Just ("X" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3, "Xb"), (5, "a")]
-- > updateMin (\ _ -> Nothing) (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
Expand Down Expand Up @@ -967,7 +967,7 @@ mapAccumRWithKey f0 a0 t0 = toPair $ go f0 a0 t0
Tip k x -> let !(a',!x') = f a k x in (a' :*: Tip k x')
Nil -> (a :*: Nil)

-- | \(O(n \log n)\).
-- | \(O(n \min(n,W))\).
-- @'mapKeysWith' c f s@ is the map obtained by applying @f@ to each key of @s@.
--
-- The size of the result may be smaller if @f@ maps two or more distinct
Expand Down

0 comments on commit 02b56b7

Please sign in to comment.