Skip to content

Commit

Permalink
Minor improvement to Map minViewSure/maxViewSure
Browse files Browse the repository at this point in the history
minViewSure/maxViewSure allocates one MinView/MaxView.
This is avoidable, by not having the local go function.
  • Loading branch information
meooow25 committed Apr 19, 2024
1 parent c651094 commit ef441e7
Showing 1 changed file with 8 additions and 14 deletions.
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

0 comments on commit ef441e7

Please sign in to comment.