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

BUG: BptreeMap range return wrong result #118

Closed
Erigara opened this issue Jun 21, 2024 · 5 comments
Closed

BUG: BptreeMap range return wrong result #118

Erigara opened this issue Jun 21, 2024 · 5 comments

Comments

@Erigara
Copy link
Contributor

Erigara commented Jun 21, 2024

Here is minimal example:

    #[test]
    fn test_bptree2_map_rangeiter_2() {
        let map = BptreeMap::from_iter([("ca", ()), ("cb", ()), ("a", ())]);

        let r = map.read();
        assert!(r.range("b"..="bb").count() == 0); // return 2
    }
@Erigara
Copy link
Contributor Author

Erigara commented Jun 24, 2024

I can work on this one

@Firstyear
Copy link
Member

Sorry I didn't get to look at this yet. I was planning to investigate this week but if you have a look first that would be great. Thanks!

@Erigara
Copy link
Contributor Author

Erigara commented Jun 25, 2024

So unfortunately my previous fix was not enough, there is more edge cases like:

#[test]
fn test_bptree2_map_rangeiter_3() {
    let map = BptreeMap::from_iter([0, 1, 2, 3, 4, 5, 6, 8].map(|v| (v, ())));

    let r = map.read();
    assert!(r.range((Bound::Excluded(6), Bound::Included(7))).count() == 0);
    assert!(r.range((Bound::Excluded(6), Bound::Excluded(8))).count() == 0);
}

From what i debugged so far it happens when two values are on the edges of adjacent leaves and when we are adjusting leaf iterators to the bounds left itrator became ahead of right iterator.

Case 1:

range: (6, 8)

         leaf 1        leaf 2
[0, 1, 2, 3, 4, 5, 6] [8, ...]
                   ^   ^
before:            L   R
after:             R   L

Case 2:

range: (6, 7]

         leaf 1        leaf 2
[0, 1, 2, 3, 4, 5, 6] [8, ...]
                   ^   ^
before:            LR  |
after:             R   L

I will try to figure out how to check this condition.

@nxsaken
Copy link

nxsaken commented Aug 15, 2024

Has this been resolved/published? @Erigara

@Firstyear
Copy link
Member

I believe it is resolved, I need to publish a new update.

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