9
9
// struct Node<K, V, height: usize> {
10
10
// keys: [K; 2 * B - 1],
11
11
// vals: [V; 2 * B - 1],
12
- // edges: if height > 0 {
13
- // [Box<Node<K, V, height - 1>>; 2 * B]
14
- // } else { () },
15
- // parent: Option<NonNull<Node<K, V, height + 1>>>,
16
- // parent_idx: u16,
12
+ // edges: [if height > 0 { Box<Node<K, V, height - 1>> } else { () }; 2 * B],
13
+ // parent: Option<(NonNull<Node<K, V, height + 1>>, u16)>,
17
14
// len: u16,
18
15
// }
19
16
// ```
28
25
//
29
26
// - Trees must have uniform depth/height. This means that every path down to a leaf from a
30
27
// given node has exactly the same length.
31
- // - A node of length `n` has `n` keys, `n` values, and (in an internal node) `n + 1` edges.
32
- // This implies that even an empty internal node has at least one edge.
28
+ // - A node of length `n` has `n` keys, `n` values, and `n + 1` edges.
29
+ // This implies that even an empty node has at least one edge.
33
30
34
31
use core:: cmp:: Ordering ;
35
32
use core:: marker:: PhantomData ;
@@ -298,9 +295,8 @@ impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
298
295
}
299
296
300
297
impl < BorrowType , K , V , Type > NodeRef < BorrowType , K , V , Type > {
301
- /// Finds the length of the node. This is the number of keys or values. In an
302
- /// internal node, the number of edges is `len() + 1`.
303
- /// For any node, the number of possible edge handles is also `len() + 1`.
298
+ /// Finds the length of the node. This is the number of keys or values.
299
+ /// The number of edges is `len() + 1`.
304
300
/// Note that, despite being safe, calling this function can have the side effect
305
301
/// of invalidating mutable references that unsafe code has created.
306
302
pub fn len ( & self ) -> usize {
@@ -321,9 +317,6 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> {
321
317
}
322
318
323
319
/// Exposes the leaf portion of any leaf or internal node.
324
- /// If the node is a leaf, this function simply opens up its data.
325
- /// If the node is an internal node, so not a leaf, it does have all the data a leaf has
326
- /// (header, keys and values), and this function exposes that.
327
320
///
328
321
/// Returns a raw ptr to avoid invalidating other references to this node,
329
322
/// which is possible when BorrowType is marker::ValMut.
@@ -471,9 +464,6 @@ impl<'a, K, V, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
471
464
}
472
465
473
466
/// Exposes the leaf portion of any leaf or internal node for writing.
474
- /// If the node is a leaf, this function simply opens up its data.
475
- /// If the node is an internal node, so not a leaf, it does have all the data a leaf has
476
- /// (header, keys and values), and this function exposes that.
477
467
///
478
468
/// We don't need to return a raw ptr because we have unique access to the entire node.
479
469
fn as_leaf_mut ( & mut self ) -> & ' a mut LeafNode < K , V > {
@@ -679,9 +669,9 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
679
669
}
680
670
681
671
impl < ' a , K : ' a , V : ' a > NodeRef < marker:: Mut < ' a > , K , V , marker:: LeafOrInternal > {
682
- /// Removes a key/value pair from the end of this node and returns the pair.
683
- /// If this is an internal node, also removes the edge that was to the right
684
- /// of that pair and returns the orphaned node that this edge owned.
672
+ /// Removes a key/value pair from the end of the node and returns the pair.
673
+ /// Also removes the edge that was to the right of that pair and, if the node
674
+ /// is internal, returns the orphaned subtree that this edge owned.
685
675
fn pop ( & mut self ) -> ( K , V , Option < Root < K , V > > ) {
686
676
debug_assert ! ( self . len( ) > 0 ) ;
687
677
@@ -705,9 +695,9 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal> {
705
695
}
706
696
}
707
697
708
- /// Removes a key/value pair from the beginning of this node and returns the pair.
709
- /// If this is an internal node, also removes the edge that was to the left
710
- /// of that pair and returns the orphaned node that this edge owned.
698
+ /// Removes a key/value pair from the beginning of the node and returns the pair.
699
+ /// Also removes the edge that was to the left of that pair and, if the node is
700
+ /// internal, returns the orphaned subtree that this edge owned.
711
701
fn pop_front ( & mut self ) -> ( K , V , Option < Root < K , V > > ) {
712
702
debug_assert ! ( self . len( ) > 0 ) ;
713
703
0 commit comments