Skip to content

Add reverse traversal#30

Merged
lgfa29 merged 5 commits into
masterfrom
reverse-traversal
Sep 16, 2020
Merged

Add reverse traversal#30
lgfa29 merged 5 commits into
masterfrom
reverse-traversal

Conversation

@lgfa29

@lgfa29 lgfa29 commented Sep 9, 2020

Copy link
Copy Markdown
Contributor

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.

@lgfa29 lgfa29 requested review from banks, cgbaker and jrasell September 9, 2020 23:15

@banks banks left a comment

Copy link
Copy Markdown
Contributor

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!

Comment thread reverse_iter.go Outdated
Comment thread reverse_iter_test.go Outdated
@lgfa29

lgfa29 commented Sep 11, 2020

Copy link
Copy Markdown
Contributor Author

@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

@banks banks left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread reverse_iter_test.go Outdated
@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