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

gaps return empty ranges #43

Closed
gzp79 opened this issue Apr 14, 2022 · 3 comments · Fixed by #45
Closed

gaps return empty ranges #43

gzp79 opened this issue Apr 14, 2022 · 3 comments · Fixed by #45

Comments

@gzp79
Copy link

gzp79 commented Apr 14, 2022

version = "1.0.1"

Gaps returns empty ranges for this simple case:

let mut ss = RangeInclusiveMap::new();
ss.insert(0u32..=0u32, 0u32);
ss.insert(1u32..=1u32, 1u32);

for v in ss.iter() {
    log::error!("in {:?}", v)
}

for v in ss.gaps(&(0u32..=u32::MAX)) {
    log::error!("gap {:?} empty: {}", v, v.is_empty())
}

output:

[2022-04-14T09:27:26Z ERROR shine_crde::operations] in (0..=0, 0)
[2022-04-14T09:27:26Z ERROR shine_crde::operations] in (1..=1, 1)
[2022-04-14T09:27:26Z ERROR shine_crde::operations] gap 1..=0 empty: true             <---- I'd not expect this response
[2022-04-14T09:27:26Z ERROR shine_crde::operations] gap 2..=4294967295 empty: false
@gzp79
Copy link
Author

gzp79 commented Apr 14, 2022

In the form of a mini test:

#[test]
fn gaps_bug() {
    let mut ss = rangemap::RangeInclusiveMap::new();
    ss.insert(0u32..=0u32, 0u32);
    ss.insert(1u32..=1u32, 1u32);

    let mut gaps = ss.gaps(&(0u32..=u32::MAX));

    // bug, should not be here, see https://github.com/jeffparsons/rangemap/issues/43
    assert_eq!(gaps.next(), Some(1u32..=0u32));   
    
    assert_eq!(gaps.next(), Some(2u32..=u32::MAX));
    assert_eq!(gaps.next(), None);
}

@jeffparsons
Copy link
Owner

Thanks for the report, @gzp-crey. I will get on to this, but a bit pressed for time right now and working on sprucing up the test suite first to make sure that this sort of thing can't sneak in in future. (Watch this space.)

jeffparsons added a commit that referenced this issue May 17, 2022
They were sometimes returning empty ranges still,
and the implementation was unnecessarily complex.
There may well have been other bugs hiding in there.

Fixes #43.

This also adds fuzzing of the gaps iterators to get
a bit more confidence that they're actually right now,
including fuzzing the size of the outer range.
@jeffparsons
Copy link
Owner

@gzp-crey This is fixed in v1.0.2. (Just pushed to crates.io.)

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

Successfully merging a pull request may close this issue.

2 participants