Skip to content

Commit

Permalink
Fix some IntMap time complexities
Browse files Browse the repository at this point in the history
IntMap.mapKeysMonotonic and IntMap.keysSet take linear time.
  • Loading branch information
meooow25 committed Jul 26, 2023
1 parent f61b0c9 commit bb5b9d8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions containers/src/Data/IntMap/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2545,7 +2545,7 @@ mapKeysWith :: (a -> a -> a) -> (Key->Key) -> IntMap a -> IntMap a
mapKeysWith c f
= fromListWith c . foldrWithKey (\k x xs -> (f k, x) : xs) []

-- | \(O(n \min(n,W))\).
-- | \(O(n)\).
-- @'mapKeysMonotonic' f s == 'mapKeys' f s@, but works only when @f@
-- is strictly monotonic.
-- That is, for any values @x@ and @y@, if @x@ < @y@ then @f x@ < @f y@.
Expand Down Expand Up @@ -3063,7 +3063,7 @@ keys = foldrWithKey (\k _ ks -> k : ks) []
assocs :: IntMap a -> [(Key,a)]
assocs = toAscList

-- | \(O(n \min(n,W))\). The set of all keys of the map.
-- | \(O(n)\). The set of all keys of the map.
--
-- > keysSet (fromList [(5,"a"), (3,"b")]) == Data.IntSet.fromList [3,5]
-- > keysSet empty == Data.IntSet.empty
Expand Down

0 comments on commit bb5b9d8

Please sign in to comment.