-
Notifications
You must be signed in to change notification settings - Fork 186
Closed
Labels
Description
updateMax, updateMaxWithKey, updateMin, updateMinWithKey for lazy and strict IntMap do not agree with Map.
IntMap errors on an empty map:
containers/containers/src/Data/IntMap/Internal.hs
Lines 2180 to 2189 in 7e7ce15
| updateMinWithKey :: (Key -> a -> Maybe a) -> IntMap a -> IntMap a | |
| updateMinWithKey f t = | |
| case t of Bin p l r | signBranch p -> binCheckRight p l (go f r) | |
| _ -> go f t | |
| where | |
| go f' (Bin p l r) = binCheckLeft p (go f' l) r | |
| go f' (Tip k y) = case f' k y of | |
| Just y' -> Tip k y' | |
| Nothing -> Nil | |
| go _ Nil = error "updateMinWithKey Nil" |
Map simply returns the empty map:
containers/containers/src/Data/Map/Internal.hs
Lines 1744 to 1749 in 7e7ce15
| updateMinWithKey :: (k -> a -> Maybe a) -> Map k a -> Map k a | |
| updateMinWithKey _ Tip = Tip | |
| updateMinWithKey f (Bin sx kx x Tip r) = case f kx x of | |
| Nothing -> r | |
| Just x' -> Bin sx kx x' Tip r | |
| updateMinWithKey f (Bin _ kx x l r) = balanceR kx x (updateMinWithKey f l) r |
The better option is that IntMap also returns an empty map.
Historical note: The Map behavior has been so since it was added in bbbba97. updateMax and friends for IntMap were added a bit later in 1a2cf0f.