@@ -861,11 +861,10 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, mark
861861 /// this edge. This method splits the node if there isn't enough room.
862862 ///
863863 /// The returned pointer points to the inserted value.
864- fn insert ( mut self , key : K , val : V ) -> ( InsertResult < ' a , K , V , marker:: Leaf > , * mut V ) {
864+ fn insert ( mut self , key : K , val : V ) -> ( Option < SplitResult < ' a , K , V , marker:: Leaf > > , * mut V ) {
865865 if self . node . len ( ) < CAPACITY {
866866 let val_ptr = self . insert_fit ( key, val) ;
867- let kv = unsafe { Handle :: new_kv ( self . node , self . idx ) } ;
868- ( InsertResult :: Fit ( kv) , val_ptr)
867+ ( None , val_ptr)
869868 } else {
870869 let ( middle_kv_idx, insertion) = splitpoint ( self . idx ) ;
871870 let middle = unsafe { Handle :: new_kv ( self . node , middle_kv_idx) } ;
@@ -879,7 +878,7 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, mark
879878 } ,
880879 } ;
881880 let val_ptr = insertion_edge. insert_fit ( key, val) ;
882- ( InsertResult :: Split ( result) , val_ptr)
881+ ( Some ( result) , val_ptr)
883882 }
884883 }
885884}
@@ -923,13 +922,12 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>,
923922 key : K ,
924923 val : V ,
925924 edge : Root < K , V > ,
926- ) -> InsertResult < ' a , K , V , marker:: Internal > {
925+ ) -> Option < SplitResult < ' a , K , V , marker:: Internal > > {
927926 assert ! ( edge. height == self . node. height - 1 ) ;
928927
929928 if self . node . len ( ) < CAPACITY {
930929 self . insert_fit ( key, val, edge) ;
931- let kv = unsafe { Handle :: new_kv ( self . node , self . idx ) } ;
932- InsertResult :: Fit ( kv)
930+ None
933931 } else {
934932 let ( middle_kv_idx, insertion) = splitpoint ( self . idx ) ;
935933 let middle = unsafe { Handle :: new_kv ( self . node , middle_kv_idx) } ;
@@ -943,7 +941,7 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>,
943941 } ,
944942 } ;
945943 insertion_edge. insert_fit ( key, val, edge) ;
946- InsertResult :: Split ( result)
944+ Some ( result)
947945 }
948946 }
949947}
@@ -953,32 +951,26 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, mark
953951 /// this edge. This method splits the node if there isn't enough room, and tries to
954952 /// insert the split off portion into the parent node recursively, until the root is reached.
955953 ///
956- /// If the returned result is a `Fit `, its handle's node can be this edge's node or an ancestor .
957- /// If the returned result is a `Split`, the `left` field will be the root node.
958- /// The returned pointer points to the inserted value .
954+ /// If the returned result is some `SplitResult `, the `left` field will be the root node.
955+ /// The returned pointer points to the inserted value, which in the case of `SplitResult`
956+ /// is in the `left` or `right` tree .
959957 pub fn insert_recursing (
960958 self ,
961959 key : K ,
962960 value : V ,
963- ) -> ( InsertResult < ' a , K , V , marker:: LeafOrInternal > , * mut V ) {
961+ ) -> ( Option < SplitResult < ' a , K , V , marker:: LeafOrInternal > > , * mut V ) {
964962 let ( mut split, val_ptr) = match self . insert ( key, value) {
965- ( InsertResult :: Fit ( handle) , ptr) => {
966- return ( InsertResult :: Fit ( handle. forget_node_type ( ) ) , ptr) ;
967- }
968- ( InsertResult :: Split ( split) , val_ptr) => ( split. forget_node_type ( ) , val_ptr) ,
963+ ( None , val_ptr) => return ( None , val_ptr) ,
964+ ( Some ( split) , val_ptr) => ( split. forget_node_type ( ) , val_ptr) ,
969965 } ;
970966
971967 loop {
972968 split = match split. left . ascend ( ) {
973969 Ok ( parent) => match parent. insert ( split. kv . 0 , split. kv . 1 , split. right ) {
974- InsertResult :: Fit ( handle) => {
975- return ( InsertResult :: Fit ( handle. forget_node_type ( ) ) , val_ptr) ;
976- }
977- InsertResult :: Split ( split) => split. forget_node_type ( ) ,
970+ None => return ( None , val_ptr) ,
971+ Some ( split) => split. forget_node_type ( ) ,
978972 } ,
979- Err ( root) => {
980- return ( InsertResult :: Split ( SplitResult { left : root, ..split } ) , val_ptr) ;
981- }
973+ Err ( root) => return ( Some ( SplitResult { left : root, ..split } ) , val_ptr) ,
982974 } ;
983975 }
984976 }
@@ -1529,14 +1521,6 @@ impl<BorrowType, K, V> Handle<NodeRef<BorrowType, K, V, marker::Leaf>, marker::K
15291521 }
15301522}
15311523
1532- impl < BorrowType , K , V > Handle < NodeRef < BorrowType , K , V , marker:: Internal > , marker:: KV > {
1533- pub fn forget_node_type (
1534- self ,
1535- ) -> Handle < NodeRef < BorrowType , K , V , marker:: LeafOrInternal > , marker:: KV > {
1536- unsafe { Handle :: new_kv ( self . node . forget_type ( ) , self . idx ) }
1537- }
1538- }
1539-
15401524impl < BorrowType , K , V , Type > Handle < NodeRef < BorrowType , K , V , marker:: LeafOrInternal > , Type > {
15411525 /// Checks whether the underlying node is an `Internal` node or a `Leaf` node.
15421526 pub fn force (
@@ -1621,7 +1605,7 @@ pub enum ForceResult<Leaf, Internal> {
16211605pub struct SplitResult < ' a , K , V , NodeType > {
16221606 // Altered node in existing tree with elements and edges that belong to the left of `kv`.
16231607 pub left : NodeRef < marker:: Mut < ' a > , K , V , NodeType > ,
1624- // Some key and value split off, to be inserted elsewhere.
1608+ // Some key and value that existed before and were split off, to be inserted elsewhere.
16251609 pub kv : ( K , V ) ,
16261610 // Owned, unattached, new node with elements and edges that belong to the right of `kv`.
16271611 pub right : NodeRef < marker:: Owned , K , V , NodeType > ,
@@ -1639,11 +1623,6 @@ impl<'a, K, V> SplitResult<'a, K, V, marker::Internal> {
16391623 }
16401624}
16411625
1642- pub enum InsertResult < ' a , K , V , NodeType > {
1643- Fit ( Handle < NodeRef < marker:: Mut < ' a > , K , V , NodeType > , marker:: KV > ) ,
1644- Split ( SplitResult < ' a , K , V , NodeType > ) ,
1645- }
1646-
16471626pub mod marker {
16481627 use core:: marker:: PhantomData ;
16491628
0 commit comments