-
Notifications
You must be signed in to change notification settings - Fork 20
[ACP] RangeBounds::overlaps #277
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
Comments
In most cases, don't people want to perform some sort of operation on the overlapping region? Could the function return a range instead? Then you could use |
@pitaj well, we'd probably need to add |
Hmm, Is it reasonable to mix the types? I guess |
Yeah, given that this is a trait and in case of intersect/overlap we would need to return a concrete type I'd say for the trait specifically it makes sense to have |
Functions like Example: Nonnegative integers can be partially ordered by divisibility, so that e.g. |
@quaternic that makes sense so it'd be
|
The function could just return Should it maybe return Like what should |
For the concrete types case, I think the right behaviour would be I'm not exactly sure how it should work for other bound combinations, though. Can we usefully define |
But taking that into account by defining
where it turns out that both |
That just means it's not Said otherwise, would a hypothetical |
Yes, the minimum of two lower bounds (or the maximum of two upper bounds) would prefer We won't be changing it now (or ever), but for the sake of discussion one could consider an alternative bound-type defined as
This wouldn't suffer from the same ambiguity, as you'd just define And the ranges would be like
|
I've implemented |
@pitaj thanks for the hard work But if you need to go through that |
Indeed. In fact, the
On the other hand, when |
Great point! I've removed that and now |
Proposal
Problem statement
RangeBounds today is a standard trait to represent ranges and provides a single method
contains
used to determine if a range contains a given element.Another common operation on ranges (like intervals) is to check if 2 overlap. Today there is no method to check for that
Motivating examples or use cases
Solution sketch
Open questions
There is a question whether to consider (Excluded(1), Excluded(3)) as overlapping with (Excluded(2), Excluded(5)).
Since this is only a problem for cases where a discrete step between elements is known we could have a specialized implementation for anything that implements
Step
that handles these cases.Alternatives
Alternative would be for developers to implement it on specific types, or an extension trait on top of RangeBounds (which could be a separate crate)
Links and related work
The text was updated successfully, but these errors were encountered: