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

crossbeam_skiplist::Range rewinds to the head after it was exhausted #1142

Open
al8n opened this issue Oct 17, 2024 · 1 comment
Open

crossbeam_skiplist::Range rewinds to the head after it was exhausted #1142

al8n opened this issue Oct 17, 2024 · 1 comment

Comments

@al8n
Copy link
Contributor

al8n commented Oct 17, 2024

Hi, I found that the implementation of the Iterator trait for Range will rewind to the head after it is exhausted. The test case below can reproduce this behavior. Is it an expected behavior or should this be a bug?

#[test]
fn range() {
    use crate::Bound::*;
    let guard = &epoch::pin();
    let s = SkipList::new(epoch::default_collector().clone());
    let v = (0..10).map(|x| x * 10).collect::<Vec<_>>();
    for &x in v.iter() {
        s.insert(x, x, guard).release(guard);
    }

    let mut it = s.range(..=5, guard);
    for _ent in &mut it {}

    let ent = it.next();
    assert!(ent.is_none(), "{ent:?}"); // panic, but why? it should be none, but yield the first element Entry(0, 0) again
}
@taiki-e
Copy link
Member

taiki-e commented Dec 8, 2024

Unless FusedIterator is implemented, the behavior of iterator after returning None is not specified. That said, it is odd to cycle back to the first element.

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

No branches or pull requests

2 participants