@@ -42,7 +42,7 @@ fn test_all_refs<'a, T: 'a>(dummy: &mut T, iter: impl Iterator<Item = &'a mut T>
42
42
}
43
43
}
44
44
45
- impl < ' a , K : ' a , V : ' a > BTreeMap < K , V > {
45
+ impl < K , V > BTreeMap < K , V > {
46
46
/// Panics if the map (or the code navigating it) is corrupted.
47
47
fn check ( & self )
48
48
where
@@ -54,14 +54,14 @@ impl<'a, K: 'a, V: 'a> BTreeMap<K, V> {
54
54
assert ! ( root_node. ascend( ) . is_err( ) ) ;
55
55
root_node. assert_back_pointers ( ) ;
56
56
57
- let counted = root_node. assert_ascending ( ) ;
58
- assert_eq ! ( self . length, counted) ;
59
57
assert_eq ! ( self . length, root_node. calc_length( ) ) ;
60
58
61
59
root_node. assert_min_len ( if root_node. height ( ) > 0 { 1 } else { 0 } ) ;
62
60
} else {
63
61
assert_eq ! ( self . length, 0 ) ;
64
62
}
63
+
64
+ self . assert_ascending ( ) ;
65
65
}
66
66
67
67
/// Returns the height of the root, if any.
@@ -79,10 +79,28 @@ impl<'a, K: 'a, V: 'a> BTreeMap<K, V> {
79
79
String :: from ( "not yet allocated" )
80
80
}
81
81
}
82
+
83
+ /// Asserts that the keys are in strictly ascending order.
84
+ fn assert_ascending ( & self )
85
+ where
86
+ K : Copy + Debug + Ord ,
87
+ {
88
+ let mut num_seen = 0 ;
89
+ let mut keys = self . keys ( ) ;
90
+ if let Some ( mut previous) = keys. next ( ) {
91
+ num_seen = 1 ;
92
+ for next in keys {
93
+ assert ! ( previous < next, "{:?} >= {:?}" , previous, next) ;
94
+ previous = next;
95
+ num_seen += 1 ;
96
+ }
97
+ }
98
+ assert_eq ! ( num_seen, self . len( ) ) ;
99
+ }
82
100
}
83
101
84
102
impl < ' a , K : ' a , V : ' a > NodeRef < marker:: Immut < ' a > , K , V , marker:: LeafOrInternal > {
85
- pub fn assert_min_len ( self , min_len : usize ) {
103
+ fn assert_min_len ( self , min_len : usize ) {
86
104
assert ! ( self . len( ) >= min_len, "{} < {}" , self . len( ) , min_len) ;
87
105
if let node:: ForceResult :: Internal ( node) = self . force ( ) {
88
106
for idx in 0 ..=node. len ( ) {
0 commit comments