-
Notifications
You must be signed in to change notification settings - Fork 186
Add a merge API for Set #1169
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
base: master
Are you sure you want to change the base?
Add a merge API for Set #1169
Conversation
To avoid the naming conflict, just like Map's link2.
This is similar to the existing API for Map.
containers/src/Data/Set/Internal.hs
Outdated
|
|
||
| filterA :: Applicative f => (a -> f Bool) -> Set a -> f (Set a) | ||
| filterA f = go | ||
| where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to start with this? I think it should help a little in general and a lot for some functors.
go t@(Bin 1 x _ _) = finish <$> f x
where
finish False = Tip
finish True = tThe extra sharing here makes me think we probably want to share any unchanged subtrees. We don't even need to use pointer equality for that, though doing so might turn out to be fastest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, updated to use ptrEq as we do in filter. I think it makes sense to keep them consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I still think you should consider special-casing a size of 1. We inherently know its subtrees don't change, plus we avoid the liftA3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point about the liftA3, done.
I expect that this is also a little faster because of #1069, but whether we should do this everywhere is still an open question.
|
I don't remember who wrote the current code for |
|
I'm not sure I see how the Personally I don't think the |
|
Good point. We probably should discuss the |
1bf4209 to
cbd43ab
Compare
For #732