Skip to content
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

Allow use of inclusive upper bound intervals. #8

Open
vext01 opened this issue Dec 8, 2020 · 2 comments
Open

Allow use of inclusive upper bound intervals. #8

vext01 opened this issue Dec 8, 2020 · 2 comments

Comments

@vext01
Copy link
Contributor

vext01 commented Dec 8, 2020

Hi,

Neat library. Thanks for writing it!

Seems that you can't use RangeInclusive intervals with the intervaltree API?

Example error messages:

error[E0308]: mismatched types
  --> yktrace/src/hwt/mapper.rs:56:24
   |
56 |                 .query(start_addr..=end_addr)
   |                        ^^^^^^^^^^^^^^^^^^^^^ expected struct `std::ops::Range`, found struct `RangeInclusive`
   |
   = note: expected struct `std::ops::Range<usize>`
              found struct `RangeInclusive<usize>`
error[E0277]: the trait bound `Element<_, _>: From<(RangeInclusive<usize>, SirLabel)>` is not satisfied
   --> yktrace/src/hwt/mapper.rs:91:5
    |
91  |     IntervalTree::from_iter(vec.into_iter().map(|l| (l.off..=l.off, l)))
    |     ^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<(RangeInclusive<usize>, SirLabel)>` is not implemented for `Element<_, _>`
    | 
   ::: /home/vext01/research/yorick/ykrustc/library/core/src/iter/traits/collect.rs:113:34
    |
113 |     fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self;
    |                                  -------- required by this bound in `from_iter`
    |
    = help: the following implementations were found:
              <Element<K, V> as From<(std::ops::Range<K>, V)>>
    = note: required because of the requirements on the impl of `Into<Element<_, _>>` for `(RangeInclusive<usize>, SirLabel)`
    = note: required because of the requirements on the impl of `FromIterator<(RangeInclusive<usize>, SirLabel)>` for `IntervalTree<_, _>`
@main--
Copy link
Owner

main-- commented Dec 13, 2020

Yes. The query function directly takes a Range and so does not accept RangeInclusive unfortunately. The reason is that the RangeBounds trait was not stable back when I wrote this library. The solution would be to make querying generic over objects implementing this trait. Then it could also work with all kinds of ranges, e.g. half-open ranges etc.

@adamreichold
Copy link

I think #12 could be a useful first step in this direction.

Personally, since I use this to index closed intervals as well, I currently help myself by just doing end: end + 1 during construction which should work if you internal boundaries have an integral type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants