Skip to content

updateMax Map/IntMap discrepancy #1061

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Tracked by #1059
meooow25 opened this issue Nov 2, 2024 · 1 comment · Fixed by #1065
Closed
Tracked by #1059

updateMax Map/IntMap discrepancy #1061

meooow25 opened this issue Nov 2, 2024 · 1 comment · Fixed by #1065

Comments

@meooow25
Copy link
Contributor

meooow25 commented Nov 2, 2024

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.

@meooow25 meooow25 added the IntMap label Nov 2, 2024
@meooow25
Copy link
Contributor Author

meooow25 commented Nov 2, 2024

Discovered when writing IntMap strictness tests for #1019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant