Skip to content

Commit fb870fd

Browse files
committed
Consolidate arena management methods in arena.rs
REORGANIZATION: - Moved all arena allocation/deallocation methods to arena.rs - Moved arena statistics and management methods to arena.rs - Moved unsafe arena access methods to arena.rs - Removed duplicates from tree_structure.rs METHODS CONSOLIDATED: ✅ allocate_leaf() & allocate_branch() (already in arena.rs) ✅ deallocate_leaf() & deallocate_branch() (moved from tree_structure.rs) ✅ free_leaf_count() & allocated_leaf_count() (moved from tree_structure.rs) ✅ free_branch_count() & allocated_branch_count() (added to arena.rs) ✅ leaf_utilization() & branch_utilization() (moved from tree_structure.rs) ✅ leaf_arena_stats() & branch_arena_stats() (moved from tree_structure.rs) ✅ set_leaf_next() (moved from tree_structure.rs) ✅ get_leaf_unchecked() & get_branch_unchecked() (moved from tree_structure.rs) RESULTS: ✅ arena.rs: 436 → 519 lines (+83 lines of arena management) ✅ tree_structure.rs: 226 → 165 lines (-61 lines, focused on structure) ✅ All 317 tests pass - 100% functionality preserved ✅ Clean compilation with no errors ✅ Better logical organization - all arena operations in one place BENEFITS: - Single source of truth for arena operations - Cleaner separation of concerns - Easier to maintain and extend arena functionality - More intuitive code organization
1 parent 0e7974e commit fb870fd

File tree

2 files changed

+86
-63
lines changed

2 files changed

+86
-63
lines changed

rust/src/arena.rs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,10 @@ pub struct ArenaDebugInfo {
299299
use crate::types::{BPlusTreeMap, LeafNode, BranchNode};
300300

301301
impl<K: Ord + Clone, V: Clone> BPlusTreeMap<K, V> {
302+
// ============================================================================
303+
// ARENA ALLOCATION METHODS
304+
// ============================================================================
305+
302306
/// Allocate a new leaf node in the arena and return its ID.
303307
pub fn allocate_leaf(&mut self, leaf: LeafNode<K, V>) -> NodeId {
304308
self.leaf_arena.allocate(leaf)
@@ -308,6 +312,86 @@ impl<K: Ord + Clone, V: Clone> BPlusTreeMap<K, V> {
308312
pub fn allocate_branch(&mut self, branch: BranchNode<K, V>) -> NodeId {
309313
self.branch_arena.allocate(branch)
310314
}
315+
316+
/// Deallocate a leaf node from the arena.
317+
pub fn deallocate_leaf(&mut self, id: NodeId) -> Option<LeafNode<K, V>> {
318+
self.leaf_arena.deallocate(id)
319+
}
320+
321+
/// Deallocate a branch node from the arena.
322+
pub fn deallocate_branch(&mut self, id: NodeId) -> Option<BranchNode<K, V>> {
323+
self.branch_arena.deallocate(id)
324+
}
325+
326+
// ============================================================================
327+
// ARENA STATISTICS AND MANAGEMENT
328+
// ============================================================================
329+
330+
/// Get the number of free leaf nodes in the arena.
331+
pub fn free_leaf_count(&self) -> usize {
332+
self.leaf_arena.free_count()
333+
}
334+
335+
/// Get the number of allocated leaf nodes in the arena.
336+
pub fn allocated_leaf_count(&self) -> usize {
337+
self.leaf_arena.allocated_count()
338+
}
339+
340+
/// Get the leaf arena utilization ratio.
341+
pub fn leaf_utilization(&self) -> f64 {
342+
self.leaf_arena.utilization()
343+
}
344+
345+
/// Get the number of free branch nodes in the arena.
346+
pub fn free_branch_count(&self) -> usize {
347+
self.branch_arena.free_count()
348+
}
349+
350+
/// Get the number of allocated branch nodes in the arena.
351+
pub fn allocated_branch_count(&self) -> usize {
352+
self.branch_arena.allocated_count()
353+
}
354+
355+
/// Get the branch arena utilization ratio.
356+
pub fn branch_utilization(&self) -> f64 {
357+
self.branch_arena.utilization()
358+
}
359+
360+
/// Get statistics for the leaf node arena.
361+
pub fn leaf_arena_stats(&self) -> crate::compact_arena::CompactArenaStats {
362+
self.leaf_arena.stats()
363+
}
364+
365+
/// Get statistics for the branch node arena.
366+
pub fn branch_arena_stats(&self) -> crate::compact_arena::CompactArenaStats {
367+
self.branch_arena.stats()
368+
}
369+
370+
/// Set the next pointer of a leaf node in the arena.
371+
pub fn set_leaf_next(&mut self, id: NodeId, next_id: NodeId) -> bool {
372+
self.get_leaf_mut(id)
373+
.map(|leaf| {
374+
leaf.next = next_id;
375+
true
376+
})
377+
.unwrap_or(false)
378+
}
379+
380+
// ============================================================================
381+
// UNSAFE ARENA ACCESS
382+
// ============================================================================
383+
384+
/// Unsafe fast access to leaf node (no bounds checking)
385+
/// SAFETY: Caller must ensure id is valid and allocated
386+
pub unsafe fn get_leaf_unchecked(&self, id: NodeId) -> &LeafNode<K, V> {
387+
self.leaf_arena.get_unchecked(id)
388+
}
389+
390+
/// Unsafe fast access to branch node (no bounds checking)
391+
/// SAFETY: Caller must ensure id is valid and allocated
392+
pub unsafe fn get_branch_unchecked(&self, id: NodeId) -> &BranchNode<K, V> {
393+
self.branch_arena.get_unchecked(id)
394+
}
311395
}
312396

313397
#[cfg(test)]

rust/src/tree_structure.rs

Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -138,54 +138,7 @@ impl<K: Ord + Clone, V: Clone> BPlusTreeMap<K, V> {
138138
}
139139
}
140140

141-
// ============================================================================
142-
// ARENA STATISTICS AND MANAGEMENT
143-
// ============================================================================
144-
145-
/// Get the number of free leaf nodes in the arena.
146-
pub fn free_leaf_count(&self) -> usize {
147-
self.leaf_arena.free_count()
148-
}
149-
150-
/// Get the number of allocated leaf nodes in the arena.
151-
pub fn allocated_leaf_count(&self) -> usize {
152-
self.leaf_arena.allocated_count()
153-
}
154-
155-
/// Get the leaf arena utilization ratio.
156-
pub fn leaf_utilization(&self) -> f64 {
157-
self.leaf_arena.utilization()
158-
}
159-
160-
/// Get statistics for the leaf node arena.
161-
pub fn leaf_arena_stats(&self) -> crate::compact_arena::CompactArenaStats {
162-
self.leaf_arena.stats()
163-
}
164-
165-
/// Get statistics for the branch node arena.
166-
pub fn branch_arena_stats(&self) -> crate::compact_arena::CompactArenaStats {
167-
self.branch_arena.stats()
168-
}
169-
170-
/// Set the next pointer of a leaf node in the arena.
171-
pub fn set_leaf_next(&mut self, id: NodeId, next_id: NodeId) -> bool {
172-
self.get_leaf_mut(id)
173-
.map(|leaf| {
174-
leaf.next = next_id;
175-
true
176-
})
177-
.unwrap_or(false)
178-
}
179-
180-
/// Deallocate a leaf node from the arena.
181-
pub fn deallocate_leaf(&mut self, id: NodeId) -> Option<LeafNode<K, V>> {
182-
self.leaf_arena.deallocate(id)
183-
}
184-
185-
/// Deallocate a branch node from the arena.
186-
pub fn deallocate_branch(&mut self, id: NodeId) -> Option<crate::types::BranchNode<K, V>> {
187-
self.branch_arena.deallocate(id)
188-
}
141+
// Arena statistics and management methods moved to arena.rs module
189142

190143
// ============================================================================
191144
// CHILD LOOKUP HELPERS
@@ -208,19 +161,5 @@ impl<K: Ord + Clone, V: Clone> BPlusTreeMap<K, V> {
208161
})
209162
}
210163

211-
// ============================================================================
212-
// UNSAFE ARENA ACCESS
213-
// ============================================================================
214-
215-
/// Unsafe fast access to leaf node (no bounds checking)
216-
/// SAFETY: Caller must ensure id is valid and allocated
217-
pub unsafe fn get_leaf_unchecked(&self, id: NodeId) -> &LeafNode<K, V> {
218-
self.leaf_arena.get_unchecked(id)
219-
}
220-
221-
/// Unsafe fast access to branch node (no bounds checking)
222-
/// SAFETY: Caller must ensure id is valid and allocated
223-
pub unsafe fn get_branch_unchecked(&self, id: NodeId) -> &crate::types::BranchNode<K, V> {
224-
self.branch_arena.get_unchecked(id)
225-
}
164+
// Unsafe arena access methods moved to arena.rs module
226165
}

0 commit comments

Comments
 (0)