@@ -43,6 +43,9 @@ use crate::boxed::Box;
4343const B : usize = 6 ;
4444pub const MIN_LEN : usize = B - 1 ;
4545pub 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 ;
4649
4750/// The underlying representation of leaf nodes.
4851#[ repr( C ) ]
@@ -834,38 +837,12 @@ enum InsertionPlace {
834837fn splitpoint ( edge_idx : usize ) -> ( usize , InsertionPlace ) {
835838 debug_assert ! ( edge_idx <= CAPACITY ) ;
836839 // 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 ) ) ) ,
864845 }
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)
869846}
870847
871848impl < ' a , K , V , NodeType > Handle < NodeRef < marker:: Mut < ' a > , K , V , NodeType > , marker:: Edge > {
@@ -1590,3 +1567,6 @@ unsafe fn slice_remove<T>(slice: &mut [T], idx: usize) -> T {
15901567 ret
15911568 }
15921569}
1570+
1571+ #[ cfg( test) ]
1572+ mod tests;
0 commit comments