@@ -43,6 +43,9 @@ use crate::boxed::Box;
43
43
const B : usize = 6 ;
44
44
pub const MIN_LEN : usize = B - 1 ;
45
45
pub const CAPACITY : usize = 2 * B - 1 ;
46
+ const KV_IDX_CENTER : usize = B - 1 ;
47
+ const EDGE_IDX_LEFT_OF_CENTER : usize = B - 1 ;
48
+ const EDGE_IDX_RIGHT_OF_CENTER : usize = B ;
46
49
47
50
/// The underlying representation of leaf nodes.
48
51
#[ repr( C ) ]
@@ -834,38 +837,12 @@ enum InsertionPlace {
834
837
fn splitpoint ( edge_idx : usize ) -> ( usize , InsertionPlace ) {
835
838
debug_assert ! ( edge_idx <= CAPACITY ) ;
836
839
// Rust issue #74834 tries to explain these symmetric rules.
837
- let middle_kv_idx;
838
- let insertion;
839
- if edge_idx <= B - 2 {
840
- middle_kv_idx = B - 2 ;
841
- insertion = InsertionPlace :: Left ( edge_idx) ;
842
- } else if edge_idx == B - 1 {
843
- middle_kv_idx = B - 1 ;
844
- insertion = InsertionPlace :: Left ( edge_idx) ;
845
- } else if edge_idx == B {
846
- middle_kv_idx = B - 1 ;
847
- insertion = InsertionPlace :: Right ( 0 ) ;
848
- } else {
849
- middle_kv_idx = B ;
850
- let new_edge_idx = edge_idx - ( B + 1 ) ;
851
- insertion = InsertionPlace :: Right ( new_edge_idx) ;
852
- }
853
- let mut left_len = middle_kv_idx;
854
- let mut right_len = CAPACITY - middle_kv_idx - 1 ;
855
- match insertion {
856
- InsertionPlace :: Left ( edge_idx) => {
857
- debug_assert ! ( edge_idx <= left_len) ;
858
- left_len += 1 ;
859
- }
860
- InsertionPlace :: Right ( edge_idx) => {
861
- debug_assert ! ( edge_idx <= right_len) ;
862
- right_len += 1 ;
863
- }
840
+ match edge_idx {
841
+ 0 ..EDGE_IDX_LEFT_OF_CENTER => ( KV_IDX_CENTER - 1 , InsertionPlace :: Left ( edge_idx) ) ,
842
+ EDGE_IDX_LEFT_OF_CENTER => ( KV_IDX_CENTER , InsertionPlace :: Left ( edge_idx) ) ,
843
+ EDGE_IDX_RIGHT_OF_CENTER => ( KV_IDX_CENTER , InsertionPlace :: Right ( 0 ) ) ,
844
+ _ => ( KV_IDX_CENTER + 1 , InsertionPlace :: Right ( edge_idx - ( KV_IDX_CENTER + 1 + 1 ) ) ) ,
864
845
}
865
- debug_assert ! ( left_len >= MIN_LEN ) ;
866
- debug_assert ! ( right_len >= MIN_LEN ) ;
867
- debug_assert ! ( left_len + right_len == CAPACITY ) ;
868
- ( middle_kv_idx, insertion)
869
846
}
870
847
871
848
impl < ' a , K , V , NodeType > Handle < NodeRef < marker:: Mut < ' a > , K , V , NodeType > , marker:: Edge > {
@@ -1594,3 +1571,6 @@ unsafe fn slice_remove<T>(slice: &mut [T], idx: usize) -> T {
1594
1571
ret
1595
1572
}
1596
1573
}
1574
+
1575
+ #[ cfg( test) ]
1576
+ mod tests;
0 commit comments