Skip to content

Inline the common case of link for Set and Map #1092

Open
@meooow25

Description

@meooow25

I'm seeing some decent improvements in union, difference, etc. on inlining the no-rebalance Bin-Bin case of link

link :: k -> a -> Map k a -> Map k a -> Map k a
link kx x Tip r = insertMin kx x r
link kx x l Tip = insertMax kx x l
link kx x l@(Bin sizeL ky y ly ry) r@(Bin sizeR kz z lz rz)
| delta*sizeL < sizeR = balanceL kz z (link kx x l lz) rz
| delta*sizeR < sizeL = balanceR ky y ly (link kx x ry r)
| otherwise = bin kx x l r

This is just like #1053, that the common case is one where no balancing is required, and making sure that's fast pays off.

I'll prepare a PR for it.

While I'm here, I'm going to change link to delegate to left-only and right-only variants of link. This better represents what's going on, i.e. link never switches directions. I've thought about this but didn't have a good reason to touch the code before.

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