crossbeam icon indicating copy to clipboard operation
crossbeam copied to clipboard

`crossbeam_skiplist::Range` rewinds to the head after it was exhausted

Open al8n opened this issue 1 year ago • 1 comments

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
}

al8n avatar Oct 17 '24 19:10 al8n

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.

taiki-e avatar Dec 08 '24 12:12 taiki-e