@@ -861,11 +861,10 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, mark
861
861
/// this edge. This method splits the node if there isn't enough room.
862
862
///
863
863
/// 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 ) {
865
865
if self . node . len ( ) < CAPACITY {
866
866
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)
869
868
} else {
870
869
let ( middle_kv_idx, insertion) = splitpoint ( self . idx ) ;
871
870
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
879
878
} ,
880
879
} ;
881
880
let val_ptr = insertion_edge. insert_fit ( key, val) ;
882
- ( InsertResult :: Split ( result) , val_ptr)
881
+ ( Some ( result) , val_ptr)
883
882
}
884
883
}
885
884
}
@@ -923,13 +922,12 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>,
923
922
key : K ,
924
923
val : V ,
925
924
edge : Root < K , V > ,
926
- ) -> InsertResult < ' a , K , V , marker:: Internal > {
925
+ ) -> Option < SplitResult < ' a , K , V , marker:: Internal > > {
927
926
assert ! ( edge. height == self . node. height - 1 ) ;
928
927
929
928
if self . node . len ( ) < CAPACITY {
930
929
self . insert_fit ( key, val, edge) ;
931
- let kv = unsafe { Handle :: new_kv ( self . node , self . idx ) } ;
932
- InsertResult :: Fit ( kv)
930
+ None
933
931
} else {
934
932
let ( middle_kv_idx, insertion) = splitpoint ( self . idx ) ;
935
933
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>,
943
941
} ,
944
942
} ;
945
943
insertion_edge. insert_fit ( key, val, edge) ;
946
- InsertResult :: Split ( result)
944
+ Some ( result)
947
945
}
948
946
}
949
947
}
@@ -953,32 +951,26 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, mark
953
951
/// this edge. This method splits the node if there isn't enough room, and tries to
954
952
/// insert the split off portion into the parent node recursively, until the root is reached.
955
953
///
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 .
959
957
pub fn insert_recursing (
960
958
self ,
961
959
key : K ,
962
960
value : V ,
963
- ) -> ( InsertResult < ' a , K , V , marker:: LeafOrInternal > , * mut V ) {
961
+ ) -> ( Option < SplitResult < ' a , K , V , marker:: LeafOrInternal > > , * mut V ) {
964
962
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) ,
969
965
} ;
970
966
971
967
loop {
972
968
split = match split. left . ascend ( ) {
973
969
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 ( ) ,
978
972
} ,
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) ,
982
974
} ;
983
975
}
984
976
}
@@ -1529,14 +1521,6 @@ impl<BorrowType, K, V> Handle<NodeRef<BorrowType, K, V, marker::Leaf>, marker::K
1529
1521
}
1530
1522
}
1531
1523
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
-
1540
1524
impl < BorrowType , K , V , Type > Handle < NodeRef < BorrowType , K , V , marker:: LeafOrInternal > , Type > {
1541
1525
/// Checks whether the underlying node is an `Internal` node or a `Leaf` node.
1542
1526
pub fn force (
@@ -1621,7 +1605,7 @@ pub enum ForceResult<Leaf, Internal> {
1621
1605
pub struct SplitResult < ' a , K , V , NodeType > {
1622
1606
// Altered node in existing tree with elements and edges that belong to the left of `kv`.
1623
1607
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.
1625
1609
pub kv : ( K , V ) ,
1626
1610
// Owned, unattached, new node with elements and edges that belong to the right of `kv`.
1627
1611
pub right : NodeRef < marker:: Owned , K , V , NodeType > ,
@@ -1639,11 +1623,6 @@ impl<'a, K, V> SplitResult<'a, K, V, marker::Internal> {
1639
1623
}
1640
1624
}
1641
1625
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
-
1647
1626
pub mod marker {
1648
1627
use core:: marker:: PhantomData ;
1649
1628
0 commit comments