You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
implemented using a fromDistinctAscList-like Stack as long as elements are non-decreasing. Once an element is out-of-order, it switches to Map.insert. (This is just want fromList does today)
However, to apply a merging function to the last key and a new key, the fromDistinctAscList's MonoState won't work because it merges the stack too eagerly. I have an implementation that removes MonoState and just uses a Stack, keeping access to the last element. Just have to test how it holds up in benchmarks.
Edit: Made a PR, #1029
containers/containers/src/Data/Map/Internal.hs
Lines 3208 to 3209 in 734785d
containers/containers/src/Data/Map/Internal.hs
Lines 3227 to 3228 in 734785d
containers/containers/src/Data/Map/Strict/Internal.hs
Lines 1454 to 1455 in 734785d
containers/containers/src/Data/IntMap/Internal.hs
Lines 2578 to 2579 in 734785d
containers/containers/src/Data/IntMap/Internal.hs
Lines 2593 to 2595 in 734785d
containers/containers/src/Data/IntMap/Strict/Internal.hs
Lines 983 to 984 in 734785d
It would be more efficient to skip the intermediate list and
foldl'
over the map accumulating into another map.An exception here is
Map.mapKeys
, sinceMap.fromList
is O(n) on an already sorted list.This raises a related question of whether
fromListWith
should also have such an optimization.The text was updated successfully, but these errors were encountered: