sstadick / sstadick/rust-lapper
Specify Range Inclusivity and Exclusivity
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 71
- Forks
- 10
- PR merge metrics
- No merged PRs in 30d
Description
I have been using Lapper quite a bit and have realized that there is one area of the API that seems a bit confusing.
Consider
let lap: Lapper<usize,usize> = Lapper::new(vec![
Interval{start:0, stop:10, val:0},
Interval{start:20, stop:30, val:1},
]);
assert_eq!(lap.find(10, 20).count(),0);
The documentation for find() states that it Find all intervals that overlap start .. stop
If I interpret that as [start,stop) then it is consistent with the definition of Interval:
/// Represent a range from [start, stop)
/// Inclusive start, exclusive of stop
pub struct Interval<I, T>
However, right now I feel like I am walking on eggshells every time I make a query because I have to ensure I am thinking about these inclusivity bounds. Something like the following would take a lot of load off the programmer.
let lap: Lapper<usize,usize> = Lapper::new(vec![
Interval{start:Inclusive::from(0), stop:Inclusive::from(10), val:0},
Interval{start:20, stop:30, val:1},
]);
assert_eq!(lap.find(Inclusive::from(10), 20).count(),1); // should just include the first one
assert_eq!(lap.find(10, Inclusive::from(20)).count(),0); // should include neither as second is not inclusive at the start
assert_eq!(lap.find(10, 21).count(),1); // should include second
/\ This is just a quick demo. I am not attached to anything like this and think it is a bit ugly. (I also want to make sure that anyone who upgrades their version is not surprised by new behavior)
You're a more experienced Rust programmer: do you know a more idiomatic way to do this? Are you at all interested in merging something that would allow for explicit inclusivity/exclusivity?
I will happily write all of the code and do all of the leg work to get this merged if we can agree on an API design.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the Interval definition and the find() API documentation, including the examples in this issue. Resolve and document an API design for explicit range inclusivity and exclusivity, while considering compatibility for existing users. Done means the behavior and upgrade impact are agreed and the corresponding API changes are specified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100