Skip to content

Simplify AllPageNumbersBtreeIter with stack-based traversal#1255

Merged
cberner merged 1 commit into
masterfrom
claude/migrate-all-pages-iter
May 13, 2026
Merged

Simplify AllPageNumbersBtreeIter with stack-based traversal#1255
cberner merged 1 commit into
masterfrom
claude/migrate-all-pages-iter

Conversation

@cberner
Copy link
Copy Markdown
Owner

@cberner cberner commented May 13, 2026

Summary

Refactored AllPageNumbersBtreeIter to use a simpler stack-based traversal approach instead of maintaining complex recursive state machines. This eliminates the RangeIterState enum and related helper functions that were only used by this iterator.

Key Changes

  • Removed RangeIterState enum and its three variants (Enter, Leaf, BranchChild) along with all associated methods
  • Removed unused helper functions: upper_bound_entry() and leaf_entries()
  • Replaced stateful traversal with a pending vector that acts as a stack of page numbers to visit
  • Simplified AllPageNumbersBtreeIter::new() to return Self directly instead of Result<Self>
  • Updated BtreeMut::all_pages_iter() return type from Result<Option<AllPageNumbersBtreeIter>> to Option<AllPageNumbersBtreeIter>
  • Removed fixed_value_size parameter from AllPageNumbersBtreeIter::new() as it's no longer needed
  • Updated all call sites in btree.rs and multimap_btree.rs to match the new signature

Implementation Details

The new implementation uses a straightforward depth-first traversal:

  • Maintains a stack (pending) of page numbers to visit
  • For each page, checks if it's a leaf (terminal) or branch node
  • For branch nodes, pushes child page numbers onto the stack in reverse order to maintain left-to-right traversal order
  • Returns each page number exactly once without complex state tracking

This approach is more maintainable and easier to understand while providing the same functionality.

https://claude.ai/code/session_01FjAnvpv4K1pPnshfkNX7Pn

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
Copy link
Copy Markdown

codecov Bot commented May 13, 2026

Codecov Report

❌ Patch coverage is 68.18182% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.34%. Comparing base (695bfde) to head (f884502).

Files with missing lines Patch % Lines
src/tree_store/btree.rs 0.00% 5 Missing ⚠️
src/tree_store/btree_iters.rs 86.66% 2 Missing ⚠️
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     
Files with missing lines Coverage Δ
src/multimap_table.rs 84.36% <ø> (+0.09%) ⬆️
src/tree_store/multimap_btree.rs 70.16% <100.00%> (-0.12%) ⬇️
src/tree_store/btree_iters.rs 96.84% <86.66%> (+4.91%) ⬆️
src/tree_store/btree.rs 86.97% <0.00%> (+0.20%) ⬆️

... and 1 file with indirect coverage changes

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

@cberner cberner merged commit 25d2db0 into master May 13, 2026
8 checks passed
@cberner cberner deleted the claude/migrate-all-pages-iter branch May 13, 2026 23:35
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.

1 participant