Skip to content

Commit b652f2f

Browse files
authored
Fix some IntMap time complexities (#967)
IntMap.mapKeysMonotonic and IntMap.keysSet take linear time.
1 parent e400579 commit b652f2f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

containers/src/Data/IntMap/Internal.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,7 +2545,7 @@ mapKeysWith :: (a -> a -> a) -> (Key->Key) -> IntMap a -> IntMap a
25452545
mapKeysWith c f
25462546
= fromListWith c . foldrWithKey (\k x xs -> (f k, x) : xs) []
25472547

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

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

0 commit comments

Comments
 (0)