-
Notifications
You must be signed in to change notification settings - Fork 144
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
Add Bitfield cut operator and other improvements #617
Conversation
utils/bitfield/src/iter/combine.rs
Outdated
impl<A, B, C> RangeIterator for _Combine<A, B, C> | ||
where | ||
A: RangeIterator, | ||
B: RangeIterator, | ||
C: Combinator, | ||
{ | ||
} | ||
|
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.
impl<A, B, C> RangeIterator for _Combine<A, B, C> | |
where | |
A: RangeIterator, | |
B: RangeIterator, | |
C: Combinator, | |
{ | |
} |
You explicitly say this is not satisfied. (I'm still a bit confused about why _Combine is even necessary) You are wrapping it as Combine(Merge(_Combine))
but does this just remove some code duplication or something?
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.
Yes, great catch, that is indeed not satisfied. Combine
does implement it, _Combine
doesn't.
The _Combine
layering is less than ideal, if trait methods could return impl Trait
then there'd be no need for a type that wraps Merge<_Combine>
. I found that integrating the Merge
code into what is now _Combine
made it a lot messier, and Merge
will indeed be able to be used elsewhere in the future (in unioning multiple bitfields, which is currently implemented very naively).
This PR adds revamped bitfield combinator logic, which was necessary for the
cut
operation, and the other combinators (union
/intersection
/difference
) benefit from it as well. Mainly:Combinator
trait that lets you concisely specify how two bitfields should be combinedCombine
range iterator that actually combines them according to the specifiedCombinator
This logic (+ explanations) can all be found in the
combine.rs
file. I also threw in the symmetric difference operation (usable with the^
and^=
operators) because of how easy it was with the new setup.The benchmarks didn't show a noticeable difference compared to before these changes.
Other changes:
BitField::{merge, intersection, difference}
methods because they returned range iterators and we didn't use them, the corresponding operators still work like beforemerge
method tounion
in order to avoid confusion with the inernalMerge
type incombine.rs
that is subtly differentbitfield/iter
module, so the diff is a bit larger than the actual changesCloses #602