The codebase currently has four NodeRef variants:
Leaf(Box<LeafNode<K, V>>)- heap-allocated leaf nodesBranch(Box<BranchNode<K, V>>)- heap-allocated branch nodesArenaLeaf(NodeId)- arena-allocated leaf nodesArenaBranch(NodeId)- arena-allocated branch nodes
The tree starts with a Leaf variant. We need to change initialization to create an arena leaf from the start.
- Change
BPlusTreeMap::new()to allocate the initial root in the arena - Update all match statements that handle
NodeRef::Leaf - Remove the
Leafvariant from the enum
- Update root promotion logic to create arena branches directly
- Remove all handling of
NodeRef::Branch - Remove the
Branchvariant from the enum
- Remove migration code paths that convert Box nodes to arena nodes
- Simplify insert/remove logic that currently handles both types
- Remove unused helper functions
- Update NodeRef enum to only have two variants
- Remove Box imports if no longer needed
- Update documentation
- Simpler code with fewer branches
- Consistent memory management
- Better cache locality
- Reduced allocator pressure
- Smaller code size
- Make changes incrementally, testing after each step
- Keep the existing arena allocation logic intact
- Ensure all 70 tests continue to pass