@@ -295,15 +295,6 @@ impl<BorrowType, K, V> NodeRef<BorrowType, K, V, marker::Internal> {
295
295
}
296
296
}
297
297
298
- impl < ' a , K , V > NodeRef < marker:: Immut < ' a > , K , V , marker:: Internal > {
299
- /// Exposes the data of an internal node in an immutable tree.
300
- fn as_internal ( this : & Self ) -> & ' a InternalNode < K , V > {
301
- let ptr = Self :: as_internal_ptr ( this) ;
302
- // SAFETY: there can be no mutable references into this tree borrowed as `Immut`.
303
- unsafe { & * ptr }
304
- }
305
- }
306
-
307
298
impl < ' a , K , V > NodeRef < marker:: Mut < ' a > , K , V , marker:: Internal > {
308
299
/// Borrows exclusive access to the data of an internal node.
309
300
fn as_internal_mut ( & mut self ) -> & mut InternalNode < K , V > {
@@ -368,17 +359,6 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Immut<'a>, K, V, Type> {
368
359
}
369
360
}
370
361
371
- impl < ' a , K , V > NodeRef < marker:: Immut < ' a > , K , V , marker:: Internal > {
372
- /// Exposes the contents of one of the edges in the node.
373
- ///
374
- /// # Safety
375
- /// The node has more than `idx` initialized elements.
376
- unsafe fn edge_at ( self , idx : usize ) -> & ' a BoxedNode < K , V > {
377
- debug_assert ! ( idx <= self . len( ) ) ;
378
- unsafe { Self :: as_internal ( & self ) . edges . get_unchecked ( idx) . assume_init_ref ( ) }
379
- }
380
- }
381
-
382
362
impl < BorrowType , K , V , Type > NodeRef < BorrowType , K , V , Type > {
383
363
/// Finds the parent of the current node. Returns `Ok(handle)` if the current
384
364
/// node actually has a parent, where `handle` points to the edge of the parent
@@ -550,31 +530,6 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
550
530
}
551
531
}
552
532
553
- impl < ' a , K : ' a , V : ' a , Type > NodeRef < marker:: Immut < ' a > , K , V , Type > {
554
- /// Exposes the entire key storage area in the node,
555
- /// regardless of the node's current length,
556
- /// having exclusive access to the entire node.
557
- unsafe fn key_area ( self ) -> & ' a [ MaybeUninit < K > ] {
558
- self . into_leaf ( ) . keys . as_slice ( )
559
- }
560
-
561
- /// Exposes the entire value storage area in the node,
562
- /// regardless of the node's current length,
563
- /// having exclusive access to the entire node.
564
- unsafe fn val_area ( self ) -> & ' a [ MaybeUninit < V > ] {
565
- self . into_leaf ( ) . vals . as_slice ( )
566
- }
567
- }
568
-
569
- impl < ' a , K : ' a , V : ' a > NodeRef < marker:: Immut < ' a > , K , V , marker:: Internal > {
570
- /// Exposes the entire storage area for edge contents in the node,
571
- /// regardless of the node's current length,
572
- /// having exclusive access to the entire node.
573
- unsafe fn edge_area ( self ) -> & ' a [ MaybeUninit < BoxedNode < K , V > > ] {
574
- Self :: as_internal ( & self ) . edges . as_slice ( )
575
- }
576
- }
577
-
578
533
impl < ' a , K , V , Type > NodeRef < marker:: ValMut < ' a > , K , V , Type > {
579
534
/// # Safety
580
535
/// - The node has more than `idx` initialized elements.
@@ -707,12 +662,12 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal> {
707
662
let idx = self . len ( ) - 1 ;
708
663
709
664
unsafe {
710
- let key = ptr :: read ( self . reborrow ( ) . key_at ( idx ) ) ;
711
- let val = ptr :: read ( self . reborrow ( ) . val_at ( idx ) ) ;
665
+ let key = self . key_area_mut_at ( idx ) . assume_init_read ( ) ;
666
+ let val = self . val_area_mut_at ( idx ) . assume_init_read ( ) ;
712
667
let edge = match self . reborrow_mut ( ) . force ( ) {
713
668
ForceResult :: Leaf ( _) => None ,
714
- ForceResult :: Internal ( internal) => {
715
- let node = ptr :: read ( internal. reborrow ( ) . edge_at ( idx + 1 ) ) ;
669
+ ForceResult :: Internal ( mut internal) => {
670
+ let node = internal. edge_area_mut_at ( idx + 1 ) . assume_init_read ( ) ;
716
671
let mut edge = Root { node, height : internal. height - 1 , _marker : PhantomData } ;
717
672
// Currently, clearing the parent link is superfluous, because we will
718
673
// insert the node elsewhere and set its parent link again.
@@ -1172,16 +1127,16 @@ impl<'a, K: 'a, V: 'a, NodeType> Handle<NodeRef<marker::Mut<'a>, K, V, NodeType>
1172
1127
let new_len = self . node . len ( ) - self . idx - 1 ;
1173
1128
new_node. len = new_len as u16 ;
1174
1129
unsafe {
1175
- let k = ptr :: read ( self . node . reborrow ( ) . key_at ( self . idx ) ) ;
1176
- let v = ptr :: read ( self . node . reborrow ( ) . val_at ( self . idx ) ) ;
1130
+ let k = self . node . key_area_mut_at ( self . idx ) . assume_init_read ( ) ;
1131
+ let v = self . node . val_area_mut_at ( self . idx ) . assume_init_read ( ) ;
1177
1132
1178
1133
ptr:: copy_nonoverlapping (
1179
- self . node . reborrow ( ) . key_area ( ) . as_ptr ( ) . add ( self . idx + 1 ) ,
1134
+ self . node . key_area_mut_at ( self . idx + 1 .. ) . as_ptr ( ) ,
1180
1135
new_node. keys . as_mut_ptr ( ) ,
1181
1136
new_len,
1182
1137
) ;
1183
1138
ptr:: copy_nonoverlapping (
1184
- self . node . reborrow ( ) . val_area ( ) . as_ptr ( ) . add ( self . idx + 1 ) ,
1139
+ self . node . val_area_mut_at ( self . idx + 1 .. ) . as_ptr ( ) ,
1185
1140
new_node. vals . as_mut_ptr ( ) ,
1186
1141
new_len,
1187
1142
) ;
@@ -1240,7 +1195,7 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>,
1240
1195
let kv = self . split_leaf_data ( & mut new_node. data ) ;
1241
1196
let new_len = usize:: from ( new_node. data . len ) ;
1242
1197
ptr:: copy_nonoverlapping (
1243
- self . node . reborrow ( ) . edge_area ( ) . as_ptr ( ) . add ( self . idx + 1 ) ,
1198
+ self . node . edge_area_mut_at ( self . idx + 1 .. ) . as_ptr ( ) ,
1244
1199
new_node. edges . as_mut_ptr ( ) ,
1245
1200
new_len + 1 ,
1246
1201
) ;
@@ -1352,7 +1307,7 @@ impl<'a, K: 'a, V: 'a> BalancingContext<'a, K, V> {
1352
1307
let old_parent_len = parent_node. len ( ) ;
1353
1308
let mut left_node = self . left_child ;
1354
1309
let old_left_len = left_node. len ( ) ;
1355
- let right_node = self . right_child ;
1310
+ let mut right_node = self . right_child ;
1356
1311
let right_len = right_node. len ( ) ;
1357
1312
let new_left_len = old_left_len + 1 + right_len;
1358
1313
@@ -1370,7 +1325,7 @@ impl<'a, K: 'a, V: 'a> BalancingContext<'a, K, V> {
1370
1325
slice_remove ( parent_node. key_area_mut_at ( ..old_parent_len) , parent_idx) ;
1371
1326
left_node. key_area_mut_at ( old_left_len) . write ( parent_key) ;
1372
1327
ptr:: copy_nonoverlapping (
1373
- right_node. reborrow ( ) . key_area ( ) . as_ptr ( ) ,
1328
+ right_node. key_area_mut_at ( .. ) . as_ptr ( ) ,
1374
1329
left_node. key_area_mut_at ( old_left_len + 1 ..) . as_mut_ptr ( ) ,
1375
1330
right_len,
1376
1331
) ;
@@ -1379,7 +1334,7 @@ impl<'a, K: 'a, V: 'a> BalancingContext<'a, K, V> {
1379
1334
slice_remove ( parent_node. val_area_mut_at ( ..old_parent_len) , parent_idx) ;
1380
1335
left_node. val_area_mut_at ( old_left_len) . write ( parent_val) ;
1381
1336
ptr:: copy_nonoverlapping (
1382
- right_node. reborrow ( ) . val_area ( ) . as_ptr ( ) ,
1337
+ right_node. val_area_mut_at ( .. ) . as_ptr ( ) ,
1383
1338
left_node. val_area_mut_at ( old_left_len + 1 ..) . as_mut_ptr ( ) ,
1384
1339
right_len,
1385
1340
) ;
@@ -1392,9 +1347,9 @@ impl<'a, K: 'a, V: 'a> BalancingContext<'a, K, V> {
1392
1347
// SAFETY: the height of the nodes being merged is one below the height
1393
1348
// of the node of this edge, thus above zero, so they are internal.
1394
1349
let mut left_node = left_node. reborrow_mut ( ) . cast_to_internal_unchecked ( ) ;
1395
- let right_node = right_node. cast_to_internal_unchecked ( ) ;
1350
+ let mut right_node = right_node. cast_to_internal_unchecked ( ) ;
1396
1351
ptr:: copy_nonoverlapping (
1397
- right_node. reborrow ( ) . edge_area ( ) . as_ptr ( ) ,
1352
+ right_node. edge_area_mut_at ( .. ) . as_ptr ( ) ,
1398
1353
left_node. edge_area_mut_at ( old_left_len + 1 ..) . as_mut_ptr ( ) ,
1399
1354
right_len + 1 ,
1400
1355
) ;
@@ -1503,7 +1458,6 @@ impl<'a, K: 'a, V: 'a> BalancingContext<'a, K, V> {
1503
1458
match ( left_node. reborrow_mut ( ) . force ( ) , right_node. reborrow_mut ( ) . force ( ) ) {
1504
1459
( ForceResult :: Internal ( left) , ForceResult :: Internal ( mut right) ) => {
1505
1460
// Make room for stolen edges.
1506
- let left = left. reborrow ( ) ;
1507
1461
let right_edges = right. edge_area_mut_at ( ..) . as_mut_ptr ( ) ;
1508
1462
ptr:: copy ( right_edges, right_edges. add ( count) , old_right_len + 1 ) ;
1509
1463
right. correct_childrens_parent_links ( count..new_right_len + 1 ) ;
@@ -1561,7 +1515,7 @@ impl<'a, K: 'a, V: 'a> BalancingContext<'a, K, V> {
1561
1515
match ( left_node. reborrow_mut ( ) . force ( ) , right_node. reborrow_mut ( ) . force ( ) ) {
1562
1516
( ForceResult :: Internal ( left) , ForceResult :: Internal ( mut right) ) => {
1563
1517
// Steal edges.
1564
- move_edges ( right. reborrow ( ) , 0 , left, old_left_len + 1 , count) ;
1518
+ move_edges ( right. reborrow_mut ( ) , 0 , left, old_left_len + 1 , count) ;
1565
1519
1566
1520
// Fill gap where stolen edges used to be.
1567
1521
let right_edges = right. edge_area_mut_at ( ..) . as_mut_ptr ( ) ;
@@ -1590,14 +1544,14 @@ unsafe fn move_kv<K, V>(
1590
1544
1591
1545
// Source and destination must have the same height.
1592
1546
unsafe fn move_edges < ' a , K : ' a , V : ' a > (
1593
- source : NodeRef < marker:: Immut < ' a > , K , V , marker:: Internal > ,
1547
+ mut source : NodeRef < marker:: Mut < ' a > , K , V , marker:: Internal > ,
1594
1548
source_offset : usize ,
1595
1549
mut dest : NodeRef < marker:: Mut < ' a > , K , V , marker:: Internal > ,
1596
1550
dest_offset : usize ,
1597
1551
count : usize ,
1598
1552
) {
1599
1553
unsafe {
1600
- let source_ptr = source. edge_area ( ) . as_ptr ( ) ;
1554
+ let source_ptr = source. edge_area_mut_at ( .. ) . as_ptr ( ) ;
1601
1555
let dest_ptr = dest. edge_area_mut_at ( dest_offset..) . as_mut_ptr ( ) ;
1602
1556
ptr:: copy_nonoverlapping ( source_ptr. add ( source_offset) , dest_ptr, count) ;
1603
1557
dest. correct_childrens_parent_links ( dest_offset..dest_offset + count) ;
@@ -1699,7 +1653,6 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal>, ma
1699
1653
1700
1654
match ( left_node. force ( ) , right_node. force ( ) ) {
1701
1655
( ForceResult :: Internal ( left) , ForceResult :: Internal ( right) ) => {
1702
- let left = left. reborrow ( ) ;
1703
1656
move_edges ( left, new_left_len + 1 , right, 1 , new_right_len) ;
1704
1657
}
1705
1658
( ForceResult :: Leaf ( _) , ForceResult :: Leaf ( _) ) => { }
0 commit comments