@@ -42,7 +42,7 @@ fn test_all_refs<'a, T: 'a>(dummy: &mut T, iter: impl Iterator<Item = &'a mut T>
4242 }
4343}
4444
45- impl < ' a , K : ' a , V : ' a > BTreeMap < K , V > {
45+ impl < K , V > BTreeMap < K , V > {
4646 /// Panics if the map (or the code navigating it) is corrupted.
4747 fn check ( & self )
4848 where
@@ -54,14 +54,14 @@ impl<'a, K: 'a, V: 'a> BTreeMap<K, V> {
5454 assert ! ( root_node. ascend( ) . is_err( ) ) ;
5555 root_node. assert_back_pointers ( ) ;
5656
57- let counted = root_node. assert_ascending ( ) ;
58- assert_eq ! ( self . length, counted) ;
5957 assert_eq ! ( self . length, root_node. calc_length( ) ) ;
6058
6159 root_node. assert_min_len ( if root_node. height ( ) > 0 { 1 } else { 0 } ) ;
6260 } else {
6361 assert_eq ! ( self . length, 0 ) ;
6462 }
63+
64+ self . assert_ascending ( ) ;
6565 }
6666
6767 /// Returns the height of the root, if any.
@@ -79,10 +79,28 @@ impl<'a, K: 'a, V: 'a> BTreeMap<K, V> {
7979 String :: from ( "not yet allocated" )
8080 }
8181 }
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+ }
82100}
83101
84102impl < ' 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 ) {
86104 assert ! ( self . len( ) >= min_len, "{} < {}" , self . len( ) , min_len) ;
87105 if let node:: ForceResult :: Internal ( node) = self . force ( ) {
88106 for idx in 0 ..=node. len ( ) {
0 commit comments