@@ -189,18 +189,40 @@ impl<K: Ord + Clone, V: Clone> BPlusTreeMap<K, V> {
189189
190190 let child_is_leaf = matches ! ( parent_branch. children[ child_index] , NodeRef :: Leaf ( _, _) ) ;
191191
192- // OPTIMIZATION: Batch sibling information gathering to minimize arena access
192+ // OPTIMIZATION: Batch sibling information gathering with direct node access
193193 let left_sibling_info = if child_index > 0 {
194194 let sibling_ref = parent_branch. children [ child_index - 1 ] . clone ( ) ;
195- let can_donate = self . check_node_can_donate ( & sibling_ref) ;
195+ let can_donate = match & sibling_ref {
196+ NodeRef :: Leaf ( id, _) => {
197+ self . get_leaf ( * id)
198+ . map ( |leaf| leaf. keys . len ( ) > leaf. min_keys ( ) )
199+ . unwrap_or ( false )
200+ }
201+ NodeRef :: Branch ( id, _) => {
202+ self . get_branch ( * id)
203+ . map ( |branch| branch. keys . len ( ) > branch. min_keys ( ) )
204+ . unwrap_or ( false )
205+ }
206+ } ;
196207 Some ( ( sibling_ref, can_donate) )
197208 } else {
198209 None
199210 } ;
200211
201212 let right_sibling_info = if child_index < parent_branch. children . len ( ) - 1 {
202213 let sibling_ref = parent_branch. children [ child_index + 1 ] . clone ( ) ;
203- let can_donate = self . check_node_can_donate ( & sibling_ref) ;
214+ let can_donate = match & sibling_ref {
215+ NodeRef :: Leaf ( id, _) => {
216+ self . get_leaf ( * id)
217+ . map ( |leaf| leaf. keys . len ( ) > leaf. min_keys ( ) )
218+ . unwrap_or ( false )
219+ }
220+ NodeRef :: Branch ( id, _) => {
221+ self . get_branch ( * id)
222+ . map ( |branch| branch. keys . len ( ) > branch. min_keys ( ) )
223+ . unwrap_or ( false )
224+ }
225+ } ;
204226 Some ( ( sibling_ref, can_donate) )
205227 } else {
206228 None
@@ -219,24 +241,6 @@ impl<K: Ord + Clone, V: Clone> BPlusTreeMap<K, V> {
219241 }
220242 }
221243
222- /// Check if a node can donate a key/value pair to a sibling
223- #[ inline]
224- fn check_node_can_donate ( & self , node_ref : & NodeRef < K , V > ) -> bool {
225- match node_ref {
226- NodeRef :: Leaf ( id, _) => {
227- // Single arena access to check if leaf can donate
228- self . get_leaf ( * id)
229- . map ( |leaf| leaf. keys . len ( ) > leaf. min_keys ( ) )
230- . unwrap_or ( false )
231- }
232- NodeRef :: Branch ( id, _) => {
233- // Single arena access to check if branch can donate
234- self . get_branch ( * id)
235- . map ( |branch| branch. keys . len ( ) > branch. min_keys ( ) )
236- . unwrap_or ( false )
237- }
238- }
239- }
240244}
241245
242246#[ cfg( test) ]
0 commit comments