Skip to content

updateMax Map/IntMap discrepancy #1061

@meooow25

Description

@meooow25

updateMax, updateMaxWithKey, updateMin, updateMinWithKey for lazy and strict IntMap do not agree with Map.

IntMap errors on an empty map:

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions