Simplify AllPageNumbersBtreeIter with stack-based traversal#1255
Merged
Conversation
AllPageNumbersBtreeIter was the last consumer of RangeIterState; it only ever ran the unbounded forward case so the state-machine plus boxed parent chain were excessive. Replace it with a Vec<PageNumber> worklist that pops a page, yields it, and pushes its branch children (in reverse so iteration order remains left-to-right pre-order). The fallible constructor goes away because no eager page fetch is needed, and the unused fixed_value_size argument is dropped at all three call sites. With RangeIterState gone, the dead upper_bound_entry / leaf_entries helpers are removed too. Assisted-by: Claude <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1255 +/- ##
==========================================
+ Coverage 88.33% 88.34% +0.01%
==========================================
Files 36 36
Lines 15022 14848 -174
==========================================
- Hits 13269 13118 -151
+ Misses 1753 1730 -23
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactored
AllPageNumbersBtreeIterto use a simpler stack-based traversal approach instead of maintaining complex recursive state machines. This eliminates theRangeIterStateenum and related helper functions that were only used by this iterator.Key Changes
RangeIterStateenum and its three variants (Enter,Leaf,BranchChild) along with all associated methodsupper_bound_entry()andleaf_entries()pendingvector that acts as a stack of page numbers to visitAllPageNumbersBtreeIter::new()to returnSelfdirectly instead ofResult<Self>BtreeMut::all_pages_iter()return type fromResult<Option<AllPageNumbersBtreeIter>>toOption<AllPageNumbersBtreeIter>fixed_value_sizeparameter fromAllPageNumbersBtreeIter::new()as it's no longer neededbtree.rsandmultimap_btree.rsto match the new signatureImplementation Details
The new implementation uses a straightforward depth-first traversal:
pending) of page numbers to visitThis approach is more maintainable and easier to understand while providing the same functionality.
https://claude.ai/code/session_01FjAnvpv4K1pPnshfkNX7Pn