@@ -111,21 +111,6 @@ impl<K, V> LeafNode<K, V> {
111
111
}
112
112
}
113
113
114
- impl < K , V > NodeHeader < K , V > {
115
- fn is_shared_root ( & self ) -> bool {
116
- ptr:: eq ( self , & EMPTY_ROOT_NODE as * const _ as * const _ )
117
- }
118
- }
119
-
120
- // We need to implement Sync here in order to make a static instance.
121
- unsafe impl Sync for NodeHeader < ( ) , ( ) > { }
122
-
123
- // An empty node used as a placeholder for the root node, to avoid allocations.
124
- // We use just a header in order to save space, since no operation on an empty tree will
125
- // ever take a pointer past the first key.
126
- static EMPTY_ROOT_NODE : NodeHeader < ( ) , ( ) > =
127
- NodeHeader { parent : ptr:: null ( ) , parent_idx : MaybeUninit :: uninit ( ) , len : 0 } ;
128
-
129
114
/// The underlying representation of internal nodes. As with `LeafNode`s, these should be hidden
130
115
/// behind `BoxedNode`s to prevent dropping uninitialized keys and values. Any pointer to an
131
116
/// `InternalNode` can be directly casted to a pointer to the underlying `LeafNode` portion of the
@@ -154,8 +139,8 @@ impl<K, V> InternalNode<K, V> {
154
139
}
155
140
156
141
/// A managed, non-null pointer to a node. This is either an owned pointer to
157
- /// `LeafNode<K, V>`, an owned pointer to `InternalNode<K, V>`, or a (not owned)
158
- /// pointer to `NodeHeader<(), ()` (more specifically, the pointer to EMPTY_ROOT_NODE).
142
+ /// `LeafNode<K, V>` or an owned pointer to `InternalNode<K, V>`.
143
+ ///
159
144
/// All of these types have a `NodeHeader<K, V>` prefix, meaning that they have at
160
145
/// least the same size as `NodeHeader<K, V>` and store the same kinds of data at the same
161
146
/// offsets; and they have a pointer alignment at least as large as `NodeHeader<K, V>`'s.
@@ -196,20 +181,6 @@ unsafe impl<K: Sync, V: Sync> Sync for Root<K, V> {}
196
181
unsafe impl < K : Send , V : Send > Send for Root < K , V > { }
197
182
198
183
impl < K , V > Root < K , V > {
199
- /// Whether the instance of `Root` wraps a shared, empty root node. If not,
200
- /// the entire tree is uniquely owned by the owner of the `Root` instance.
201
- pub fn is_shared_root ( & self ) -> bool {
202
- self . as_ref ( ) . is_shared_root ( )
203
- }
204
-
205
- /// Returns a shared tree, wrapping a shared root node that is eternally empty.
206
- pub fn shared_empty_root ( ) -> Self {
207
- Root {
208
- node : unsafe { BoxedNode :: from_ptr ( NonNull :: from ( & EMPTY_ROOT_NODE ) . cast ( ) ) } ,
209
- height : 0 ,
210
- }
211
- }
212
-
213
184
/// Returns a new owned tree, with its own root node that is initially empty.
214
185
pub fn new_leaf ( ) -> Self {
215
186
Root { node : BoxedNode :: from_leaf ( Box :: new ( unsafe { LeafNode :: new ( ) } ) ) , height : 0 }
@@ -245,7 +216,6 @@ impl<K, V> Root<K, V> {
245
216
/// Adds a new internal node with a single edge, pointing to the previous root, and make that
246
217
/// new node the root. This increases the height by 1 and is the opposite of `pop_level`.
247
218
pub fn push_level ( & mut self ) -> NodeRef < marker:: Mut < ' _ > , K , V , marker:: Internal > {
248
- debug_assert ! ( !self . is_shared_root( ) ) ;
249
219
let mut new_node = Box :: new ( unsafe { InternalNode :: new ( ) } ) ;
250
220
new_node. edges [ 0 ] . write ( unsafe { BoxedNode :: from_ptr ( self . node . as_ptr ( ) ) } ) ;
251
221
@@ -381,19 +351,13 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> {
381
351
/// Unsafe because the node must not be the shared root. For more information,
382
352
/// see the `NodeRef` comments.
383
353
unsafe fn as_leaf ( & self ) -> & LeafNode < K , V > {
384
- debug_assert ! ( !self . is_shared_root( ) ) ;
385
354
self . node . as_ref ( )
386
355
}
387
356
388
357
fn as_header ( & self ) -> & NodeHeader < K , V > {
389
358
unsafe { & * ( self . node . as_ptr ( ) as * const NodeHeader < K , V > ) }
390
359
}
391
360
392
- /// Returns whether the node is the shared, empty root.
393
- pub fn is_shared_root ( & self ) -> bool {
394
- self . as_header ( ) . is_shared_root ( )
395
- }
396
-
397
361
/// Borrows a view into the keys stored in the node.
398
362
/// Unsafe because the caller must ensure that the node is not the shared root.
399
363
pub unsafe fn keys ( & self ) -> & [ K ] {
@@ -464,7 +428,6 @@ impl<K, V> NodeRef<marker::Owned, K, V, marker::LeafOrInternal> {
464
428
pub unsafe fn deallocate_and_ascend (
465
429
self ,
466
430
) -> Option < Handle < NodeRef < marker:: Owned , K , V , marker:: Internal > , marker:: Edge > > {
467
- assert ! ( !self . is_shared_root( ) ) ;
468
431
let height = self . height ;
469
432
let node = self . node ;
470
433
let ret = self . ascend ( ) . ok ( ) ;
@@ -527,14 +490,12 @@ impl<'a, K, V, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
527
490
impl < ' a , K : ' a , V : ' a , Type > NodeRef < marker:: Immut < ' a > , K , V , Type > {
528
491
/// Unsafe because the caller must ensure that the node is not the shared root.
529
492
unsafe fn into_key_slice ( self ) -> & ' a [ K ] {
530
- debug_assert ! ( !self . is_shared_root( ) ) ;
531
493
// We cannot be the shared root, so `as_leaf` is okay.
532
494
slice:: from_raw_parts ( MaybeUninit :: first_ptr ( & self . as_leaf ( ) . keys ) , self . len ( ) )
533
495
}
534
496
535
497
/// Unsafe because the caller must ensure that the node is not the shared root.
536
498
unsafe fn into_val_slice ( self ) -> & ' a [ V ] {
537
- debug_assert ! ( !self . is_shared_root( ) ) ;
538
499
// We cannot be the shared root, so `as_leaf` is okay.
539
500
slice:: from_raw_parts ( MaybeUninit :: first_ptr ( & self . as_leaf ( ) . vals ) , self . len ( ) )
540
501
}
@@ -555,7 +516,6 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
555
516
556
517
/// Unsafe because the caller must ensure that the node is not the shared root.
557
518
unsafe fn into_key_slice_mut ( mut self ) -> & ' a mut [ K ] {
558
- debug_assert ! ( !self . is_shared_root( ) ) ;
559
519
// We cannot be the shared root, so `as_leaf_mut` is okay.
560
520
slice:: from_raw_parts_mut (
561
521
MaybeUninit :: first_ptr_mut ( & mut ( * self . as_leaf_mut ( ) ) . keys ) ,
@@ -565,7 +525,6 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
565
525
566
526
/// Unsafe because the caller must ensure that the node is not the shared root.
567
527
unsafe fn into_val_slice_mut ( mut self ) -> & ' a mut [ V ] {
568
- debug_assert ! ( !self . is_shared_root( ) ) ;
569
528
slice:: from_raw_parts_mut (
570
529
MaybeUninit :: first_ptr_mut ( & mut ( * self . as_leaf_mut ( ) ) . vals ) ,
571
530
self . len ( ) ,
@@ -574,7 +533,6 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
574
533
575
534
/// Unsafe because the caller must ensure that the node is not the shared root.
576
535
unsafe fn into_slices_mut ( mut self ) -> ( & ' a mut [ K ] , & ' a mut [ V ] ) {
577
- debug_assert ! ( !self . is_shared_root( ) ) ;
578
536
// We cannot use the getters here, because calling the second one
579
537
// invalidates the reference returned by the first.
580
538
// More precisely, it is the call to `len` that is the culprit,
@@ -592,7 +550,6 @@ impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::Leaf> {
592
550
/// Adds a key/value pair the end of the node.
593
551
pub fn push ( & mut self , key : K , val : V ) {
594
552
assert ! ( self . len( ) < CAPACITY ) ;
595
- debug_assert ! ( !self . is_shared_root( ) ) ;
596
553
597
554
let idx = self . len ( ) ;
598
555
@@ -607,7 +564,6 @@ impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::Leaf> {
607
564
/// Adds a key/value pair to the beginning of the node.
608
565
pub fn push_front ( & mut self , key : K , val : V ) {
609
566
assert ! ( self . len( ) < CAPACITY ) ;
610
- debug_assert ! ( !self . is_shared_root( ) ) ;
611
567
612
568
unsafe {
613
569
slice_insert ( self . keys_mut ( ) , 0 , key) ;
@@ -624,7 +580,6 @@ impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
624
580
pub fn push ( & mut self , key : K , val : V , edge : Root < K , V > ) {
625
581
assert ! ( edge. height == self . height - 1 ) ;
626
582
assert ! ( self . len( ) < CAPACITY ) ;
627
- debug_assert ! ( !self . is_shared_root( ) ) ;
628
583
629
584
let idx = self . len ( ) ;
630
585
@@ -658,7 +613,6 @@ impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
658
613
pub fn push_front ( & mut self , key : K , val : V , edge : Root < K , V > ) {
659
614
assert ! ( edge. height == self . height - 1 ) ;
660
615
assert ! ( self . len( ) < CAPACITY ) ;
661
- debug_assert ! ( !self . is_shared_root( ) ) ;
662
616
663
617
unsafe {
664
618
slice_insert ( self . keys_mut ( ) , 0 , key) ;
@@ -904,7 +858,6 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, marker::Edge
904
858
fn insert_fit ( & mut self , key : K , val : V ) -> * mut V {
905
859
// Necessary for correctness, but in a private module
906
860
debug_assert ! ( self . node. len( ) < CAPACITY ) ;
907
- debug_assert ! ( !self . node. is_shared_root( ) ) ;
908
861
909
862
unsafe {
910
863
slice_insert ( self . node . keys_mut ( ) , self . idx , key) ;
@@ -1081,7 +1034,6 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, marker::KV>
1081
1034
/// - All the key/value pairs to the right of this handle are put into a newly
1082
1035
/// allocated node.
1083
1036
pub fn split ( mut self ) -> ( NodeRef < marker:: Mut < ' a > , K , V , marker:: Leaf > , K , V , Root < K , V > ) {
1084
- assert ! ( !self . node. is_shared_root( ) ) ;
1085
1037
unsafe {
1086
1038
let mut new_node = Box :: new ( LeafNode :: new ( ) ) ;
1087
1039
@@ -1113,7 +1065,6 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, marker::KV>
1113
1065
pub fn remove (
1114
1066
mut self ,
1115
1067
) -> ( Handle < NodeRef < marker:: Mut < ' a > , K , V , marker:: Leaf > , marker:: Edge > , K , V ) {
1116
- assert ! ( !self . node. is_shared_root( ) ) ;
1117
1068
unsafe {
1118
1069
let k = slice_remove ( self . node . keys_mut ( ) , self . idx ) ;
1119
1070
let v = slice_remove ( self . node . vals_mut ( ) , self . idx ) ;
0 commit comments