wvwwvwwv / scalable-concurrent-containers

High performance containers and utilities for concurrent and asynchronous programming
Apache License 2.0
285 stars 14 forks source link

TreeIndex range edge case: Range start is lower than first element in TreeIndex #115

Closed skittishdev closed 8 months ago

skittishdev commented 8 months ago

Hello,

First off, thank you for this awesome crate.

I noticed some odd behavior recently when using TreeIndex while attempting to retrieve a range using bounds where the lower bound is smaller than the first key in the TreeIndex. That's a lot of words. So, here is a minimal example which should be easier to follow.

Minimal example

use scc::{ebr::Guard, TreeIndex};

fn main() -> Result<(), (u64, String)> {
    let index: TreeIndex<u64, String> = TreeIndex::new();
    index.insert(5, "Hello".to_string())?;
    index.insert(10, "World".to_string())?;
    index.insert(12, "FooBar".to_string())?;

    let guard = Guard::new();
    println!("Happy case. Expected: 1, Actual: {}", index.range(6..=10, &guard).count());
    println!("Buggy case. Expected: 1, Actual: {}", index.range(2..=6, &guard).count());
    println!("Workaround for bug: Expected: 1, Actual: {}", index.range(..=6, &guard).count());
    Ok(())
}

Output

Happy case. Expected: 1, Actual: 1
Buggy case. Expected: 1, Actual: 0
Workaround for bug: Expected: 1, Actual: 1

Asks

I believe that this is a bug, and should be fixed. At the very least, it should be documented. I apologize if it is already called out, and I missed it somehow.

wvwwvwwv commented 8 months ago

Thanks for finding this out! It's definitely a bug, a serious one, and I'll fix it by the end of this week.

wvwwvwwv commented 8 months ago

Fixed in 2.0.4!