@@ -1355,66 +1355,65 @@ impl<'a, K: 'a, V: 'a> BalancingContext<'a, K, V> {
13551355/// 
13561356/// Panics unless we `.can_merge()`. 
13571357pub  fn  merge ( 
1358-         mut   self , 
1358+         self , 
13591359        track_edge_idx :  Option < LeftOrRight < usize > > , 
13601360    )  -> Handle < NodeRef < marker:: Mut < ' a > ,  K ,  V ,  marker:: LeafOrInternal > ,  marker:: Edge >  { 
1361+         let  Handle  {  node :  mut  parent_node,  idx :  parent_idx,  _marker }  = self . parent ; 
1362+         let  old_parent_len = parent_node. len ( ) ; 
13611363        let  mut  left_node = self . left_child ; 
1362-         let  left_len  = left_node. len ( ) ; 
1364+         let  old_left_len  = left_node. len ( ) ; 
13631365        let  right_node = self . right_child ; 
13641366        let  right_len = right_node. len ( ) ; 
1367+         let  new_left_len = old_left_len + 1  + right_len; 
13651368
1366-         assert ! ( left_len + right_len <  CAPACITY ) ; 
1369+         assert ! ( new_left_len <=  CAPACITY ) ; 
13671370        assert ! ( match  track_edge_idx { 
13681371            None  => true , 
1369-             Some ( LeftOrRight :: Left ( idx) )  => idx <= left_len , 
1372+             Some ( LeftOrRight :: Left ( idx) )  => idx <= old_left_len , 
13701373            Some ( LeftOrRight :: Right ( idx) )  => idx <= right_len, 
13711374        } ) ; 
13721375
13731376        unsafe  { 
1374-             * left_node. reborrow_mut ( ) . into_len_mut ( )  += right_len  as  u16  +  1 ; 
1377+             * left_node. reborrow_mut ( ) . into_len_mut ( )  = new_left_len  as  u16 ; 
13751378
1376-             let  parent_key = slice_remove ( 
1377-                 self . parent . node . reborrow_mut ( ) . into_key_area_slice ( ) , 
1378-                 self . parent . idx , 
1379-             ) ; 
1380-             left_node. reborrow_mut ( ) . into_key_area_mut_at ( left_len) . write ( parent_key) ; 
1379+             let  parent_key =
1380+                 slice_remove ( parent_node. reborrow_mut ( ) . into_key_area_slice ( ) ,  parent_idx) ; 
1381+             left_node. reborrow_mut ( ) . into_key_area_mut_at ( old_left_len) . write ( parent_key) ; 
13811382            ptr:: copy_nonoverlapping ( 
13821383                right_node. reborrow ( ) . key_area ( ) . as_ptr ( ) , 
1383-                 left_node. reborrow_mut ( ) . into_key_area_slice ( ) . as_mut_ptr ( ) . add ( left_len  + 1 ) , 
1384+                 left_node. reborrow_mut ( ) . into_key_area_slice ( ) . as_mut_ptr ( ) . add ( old_left_len  + 1 ) , 
13841385                right_len, 
13851386            ) ; 
13861387
1387-             let  parent_val = slice_remove ( 
1388-                 self . parent . node . reborrow_mut ( ) . into_val_area_slice ( ) , 
1389-                 self . parent . idx , 
1390-             ) ; 
1391-             left_node. reborrow_mut ( ) . into_val_area_mut_at ( left_len) . write ( parent_val) ; 
1388+             let  parent_val =
1389+                 slice_remove ( parent_node. reborrow_mut ( ) . into_val_area_slice ( ) ,  parent_idx) ; 
1390+             left_node. reborrow_mut ( ) . into_val_area_mut_at ( old_left_len) . write ( parent_val) ; 
13921391            ptr:: copy_nonoverlapping ( 
13931392                right_node. reborrow ( ) . val_area ( ) . as_ptr ( ) , 
1394-                 left_node. reborrow_mut ( ) . into_val_area_slice ( ) . as_mut_ptr ( ) . add ( left_len  + 1 ) , 
1393+                 left_node. reborrow_mut ( ) . into_val_area_slice ( ) . as_mut_ptr ( ) . add ( old_left_len  + 1 ) , 
13951394                right_len, 
13961395            ) ; 
13971396
1398-             slice_remove ( 
1399-                 & mut  self . parent . node . reborrow_mut ( ) . into_edge_area_slice ( ) , 
1400-                 self . parent . idx  + 1 , 
1401-             ) ; 
1402-             let  parent_old_len = self . parent . node . len ( ) ; 
1403-             self . parent . node . correct_childrens_parent_links ( self . parent . idx  + 1 ..parent_old_len) ; 
1404-             * self . parent . node . reborrow_mut ( ) . into_len_mut ( )  -= 1 ; 
1397+             slice_remove ( & mut  parent_node. reborrow_mut ( ) . into_edge_area_slice ( ) ,  parent_idx + 1 ) ; 
1398+             parent_node. correct_childrens_parent_links ( parent_idx + 1 ..old_parent_len) ; 
1399+             * parent_node. reborrow_mut ( ) . into_len_mut ( )  -= 1 ; 
14051400
1406-             if  self . parent . node . height  > 1  { 
1401+             if  parent_node . height  > 1  { 
14071402                // SAFETY: the height of the nodes being merged is one below the height 
14081403                // of the node of this edge, thus above zero, so they are internal. 
14091404                let  mut  left_node = left_node. reborrow_mut ( ) . cast_to_internal_unchecked ( ) ; 
14101405                let  right_node = right_node. cast_to_internal_unchecked ( ) ; 
14111406                ptr:: copy_nonoverlapping ( 
14121407                    right_node. reborrow ( ) . edge_area ( ) . as_ptr ( ) , 
1413-                     left_node. reborrow_mut ( ) . into_edge_area_slice ( ) . as_mut_ptr ( ) . add ( left_len + 1 ) , 
1408+                     left_node
1409+                         . reborrow_mut ( ) 
1410+                         . into_edge_area_slice ( ) 
1411+                         . as_mut_ptr ( ) 
1412+                         . add ( old_left_len + 1 ) , 
14141413                    right_len + 1 , 
14151414                ) ; 
14161415
1417-                 left_node. correct_childrens_parent_links ( left_len  + 1 ..=left_len  + 1  + right_len ) ; 
1416+                 left_node. correct_childrens_parent_links ( old_left_len  + 1 ..new_left_len  + 1 ) ; 
14181417
14191418                Global . deallocate ( right_node. node . cast ( ) ,  Layout :: new :: < InternalNode < K ,  V > > ( ) ) ; 
14201419            }  else  { 
@@ -1424,7 +1423,7 @@ impl<'a, K: 'a, V: 'a> BalancingContext<'a, K, V> {
14241423            let  new_idx = match  track_edge_idx { 
14251424                None  => 0 , 
14261425                Some ( LeftOrRight :: Left ( idx) )  => idx, 
1427-                 Some ( LeftOrRight :: Right ( idx) )  => left_len  + 1  + idx, 
1426+                 Some ( LeftOrRight :: Right ( idx) )  => old_left_len  + 1  + idx, 
14281427            } ; 
14291428            Handle :: new_edge ( left_node,  new_idx) 
14301429        } 
0 commit comments