@@ -5,25 +5,26 @@ use crate::string::String;
55use core:: cmp:: Ordering :: * ;
66
77impl < ' a , K : ' a , V : ' a > NodeRef < marker:: Immut < ' a > , K , V , marker:: LeafOrInternal > {
8+ /// Asserts that the back pointer in each reachable node points to its parent.
89 pub fn assert_back_pointers ( self ) {
9- match self . force ( ) {
10- ForceResult :: Leaf ( _) => { }
11- ForceResult :: Internal ( node) => {
12- for idx in 0 ..=node. len ( ) {
13- let edge = unsafe { Handle :: new_edge ( node, idx) } ;
14- let child = edge. descend ( ) ;
15- assert ! ( child. ascend( ) . ok( ) == Some ( edge) ) ;
16- child. assert_back_pointers ( ) ;
17- }
10+ if let ForceResult :: Internal ( node) = self . force ( ) {
11+ for idx in 0 ..=node. len ( ) {
12+ let edge = unsafe { Handle :: new_edge ( node, idx) } ;
13+ let child = edge. descend ( ) ;
14+ assert ! ( child. ascend( ) . ok( ) == Some ( edge) ) ;
15+ child. assert_back_pointers ( ) ;
1816 }
1917 }
2018 }
2119
22- pub fn assert_ascending ( self )
20+ /// Asserts that the keys are in strictly ascending order.
21+ /// Returns how many keys it encountered.
22+ pub fn assert_ascending ( self ) -> usize
2323 where
2424 K : Copy + Debug + Ord ,
2525 {
2626 struct SeriesChecker < T > {
27+ num_seen : usize ,
2728 previous : Option < T > ,
2829 }
2930 impl < T : Copy + Debug + Ord > SeriesChecker < T > {
@@ -32,10 +33,11 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Immut<'a>, K, V, marker::LeafOrInternal>
3233 assert ! ( previous < next, "{:?} >= {:?}" , previous, next) ;
3334 }
3435 self . previous = Some ( next) ;
36+ self . num_seen += 1 ;
3537 }
3638 }
3739
38- let mut checker = SeriesChecker { previous : None } ;
40+ let mut checker = SeriesChecker { num_seen : 0 , previous : None } ;
3941 self . visit_nodes_in_order ( |pos| match pos {
4042 navigate:: Position :: Leaf ( node) => {
4143 for idx in 0 ..node. len ( ) {
@@ -49,33 +51,7 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Immut<'a>, K, V, marker::LeafOrInternal>
4951 }
5052 navigate:: Position :: Internal ( _) => { }
5153 } ) ;
52- }
53-
54- pub fn assert_and_add_lengths ( self ) -> usize {
55- let mut internal_length = 0 ;
56- let mut internal_kv_count = 0 ;
57- let mut leaf_length = 0 ;
58- self . visit_nodes_in_order ( |pos| match pos {
59- navigate:: Position :: Leaf ( node) => {
60- let is_root = self . height ( ) == 0 ;
61- let min_len = if is_root { 0 } else { MIN_LEN } ;
62- assert ! ( node. len( ) >= min_len, "{} < {}" , node. len( ) , min_len) ;
63- leaf_length += node. len ( ) ;
64- }
65- navigate:: Position :: Internal ( node) => {
66- let is_root = self . height ( ) == node. height ( ) ;
67- let min_len = if is_root { 1 } else { MIN_LEN } ;
68- assert ! ( node. len( ) >= min_len, "{} < {}" , node. len( ) , min_len) ;
69- internal_length += node. len ( ) ;
70- }
71- navigate:: Position :: InternalKV ( _) => {
72- internal_kv_count += 1 ;
73- }
74- } ) ;
75- assert_eq ! ( internal_length, internal_kv_count) ;
76- let total = internal_length + leaf_length;
77- assert_eq ! ( self . calc_length( ) , total) ;
78- total
54+ checker. num_seen
7955 }
8056
8157 pub fn dump_keys ( self ) -> String
@@ -124,8 +100,8 @@ fn test_splitpoint() {
124100 right_len += 1 ;
125101 }
126102 }
127- assert ! ( left_len >= MIN_LEN ) ;
128- assert ! ( right_len >= MIN_LEN ) ;
103+ assert ! ( left_len >= MIN_LEN_AFTER_SPLIT ) ;
104+ assert ! ( right_len >= MIN_LEN_AFTER_SPLIT ) ;
129105 assert ! ( left_len + right_len == CAPACITY ) ;
130106 }
131107}
0 commit comments