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

refactor PathIterator::check_validity; add tests #642

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

danlaine
Copy link
Contributor

I have an easier time conceptualizing the validity condition in the way I described in the comments. If you feel like this will make the code easier to understand, great. Otherwise, feel free to just keep the tests.

// If it's bigger than the remaining size, it's not in this range.
let mountain_size = (1 << (height + 1)) - 1;
if size >= mountain_size {
size -= mountain_size;
Copy link
Collaborator

@roberto-bayardo roberto-bayardo Mar 22, 2025

Choose a reason for hiding this comment

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

why not instead return immediately if mountain_size > size? [Edit: Oh does this mean there's no "peak" with the current height and hence no mountain of this size actually exists? If so please add a comment to the effect.]

Ah I see I didn't interpret "range" in your comment as "mountain range" but rather a more generic "range of values"! Perhaps reword your comment as:

// Subtract the size of the next mountain if it's part of this mountain range (mountain_size < size)


// Height of the root of the smallest perfect binary
// tree containing `size` (leaf is height 0)
let mut height = 63 - size.leading_zeros();
Copy link
Collaborator

Choose a reason for hiding this comment

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

While this is more clear in isolation, given the rest of the iterator implementations maintain 2^(height+1) as "two_h" instead of converting height directly with each iteration, it might be best to stick with that & save a few cycles of computation each iteration.

@roberto-bayardo
Copy link
Collaborator

General nit: Please format comments to 100 columns to match rest of the file. (If you use vscode I recommend the Rewrap extension.)

Copy link

codecov bot commented Mar 26, 2025

Codecov Report

Attention: Patch coverage is 95.45455% with 2 lines in your changes missing coverage. Please review.

Project coverage is 89.42%. Comparing base (dfb7e79) to head (4a31f92).
Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
storage/src/mmr/iterator.rs 95.45% 2 Missing ⚠️
@@           Coverage Diff            @@
##             main     #642    +/-   ##
========================================
  Coverage   89.41%   89.42%            
========================================
  Files         144      145     +1     
  Lines       36754    37033   +279     
========================================
+ Hits        32865    33117   +252     
- Misses       3889     3916    +27     
Files with missing lines Coverage Δ
storage/src/mmr/iterator.rs 97.22% <95.45%> (-0.59%) ⬇️

... and 6 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dfb7e79...4a31f92. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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