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

Add reverse traversal #30

Merged
merged 5 commits into from
Sep 16, 2020
Merged

Add reverse traversal #30

merged 5 commits into from
Sep 16, 2020

Conversation

lgfa29
Copy link
Contributor

@lgfa29 lgfa29 commented Sep 9, 2020

This PR implements reverse tree traversal.

It introduces a new type of Iterator called ReverseIterator that can move through a tree in reverse order using the Previous() and SeekReverseLowerBound() methods.

It also adds a new WalkBackwards() method to Node that works the same way as Walk() but in reverse, going from the largest to the lowest values.

Copy link
Member

@banks banks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking really good!

I suggest a fuzz test to exercise more of the edges and possibly found a bug but I could be wrong!

reverse_iter.go Outdated Show resolved Hide resolved
reverse_iter_test.go Outdated Show resolved Hide resolved
@lgfa29
Copy link
Contributor Author

lgfa29 commented Sep 11, 2020

@banks I added fuzz tests for the ReverseIterator. It was super helpful, so thanks for the tip.

I noticed that the recurse bug is only triggered when the seek starts from a non-root node, so I added two tests. There's a comment explaining why this is the case. I hope the explanation is clear enough, otherwise I can expand it. It's kind of an unusual case, but I guess not impossible, so worth testing.

The two tests are very similar, but they are different enough that I couldn't find a nice way to re-use things, I hope that's OK.

@lgfa29 lgfa29 requested a review from banks September 11, 2020 00:52
Copy link
Member

@banks banks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job Luiz!

I think it could be possible to work the two fuzz tests into one with some random bool input that chooses wether or not to try to start at a non-root node. Then both paths would be exercised with high probability in any given run (check runs 1000 iterations by default IIRC).

That said, I don't think it's especially problematic to have them separate either so accepting for now.

reverse_iter_test.go Outdated Show resolved Hide resolved
@cgbaker cgbaker removed their request for review September 14, 2020 19:00
@lgfa29 lgfa29 merged commit 0528b9c into master Sep 16, 2020
@lgfa29 lgfa29 deleted the reverse-traversal branch September 16, 2020 15:17
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 this pull request may close these issues.

2 participants