Skip to content
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

Improve Map minViewSure/maxViewSure #1001

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions containers/src/Data/Map/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4015,22 +4015,16 @@ data MinView k a = MinView !k a !(Map k a)
data MaxView k a = MaxView !k a !(Map k a)

minViewSure :: k -> a -> Map k a -> Map k a -> MinView k a
minViewSure = go
where
go k x Tip r = MinView k x r
go k x (Bin _ kl xl ll lr) r =
case go kl xl ll lr of
MinView km xm l' -> MinView km xm (balanceR k x l' r)
{-# NOINLINE minViewSure #-}
minViewSure !k x l !r = case l of
Tip -> MinView k x r
Bin _ lk lx ll lr -> case minViewSure lk lx ll lr of
MinView km xm l' -> MinView km xm (balanceR k x l' r)

maxViewSure :: k -> a -> Map k a -> Map k a -> MaxView k a
maxViewSure = go
where
go k x l Tip = MaxView k x l
go k x l (Bin _ kr xr rl rr) =
case go kr xr rl rr of
MaxView km xm r' -> MaxView km xm (balanceL k x l r')
{-# NOINLINE maxViewSure #-}
maxViewSure !k x !l r = case r of
Tip -> MaxView k x l
Bin _ rk rx rl rr -> case maxViewSure rk rx rl rr of
MaxView km xm r' -> MaxView km xm (balanceL k x l r')

-- | \(O(\log n)\). Delete and find the minimal element.
--
Expand Down
Loading