1
- use super :: super :: { navigate :: Position , node, DeterministicRng } ;
1
+ use super :: super :: { node, DeterministicRng } ;
2
2
use super :: Entry :: { Occupied , Vacant } ;
3
3
use super :: * ;
4
4
use crate :: boxed:: Box ;
@@ -7,7 +7,7 @@ use crate::rc::Rc;
7
7
use crate :: string:: { String , ToString } ;
8
8
use crate :: vec:: Vec ;
9
9
use std:: convert:: TryFrom ;
10
- use std:: iter:: FromIterator ;
10
+ use std:: iter:: { self , FromIterator } ;
11
11
use std:: mem;
12
12
use std:: ops:: Bound :: { self , Excluded , Included , Unbounded } ;
13
13
use std:: ops:: RangeBounds ;
@@ -42,19 +42,6 @@ fn test_all_refs<'a, T: 'a>(dummy: &mut T, iter: impl Iterator<Item = &'a mut T>
42
42
}
43
43
}
44
44
45
- struct SeriesChecker < T > {
46
- previous : Option < T > ,
47
- }
48
-
49
- impl < T : Copy + Debug + Ord > SeriesChecker < T > {
50
- fn is_ascending ( & mut self , next : T ) {
51
- if let Some ( previous) = self . previous {
52
- assert ! ( previous < next, "{:?} >= {:?}" , previous, next) ;
53
- }
54
- self . previous = Some ( next) ;
55
- }
56
- }
57
-
58
45
impl < ' a , K : ' a , V : ' a > BTreeMap < K , V > {
59
46
/// Panics if the map (or the code navigating it) is corrupted.
60
47
fn check ( & self )
@@ -63,44 +50,10 @@ impl<'a, K: 'a, V: 'a> BTreeMap<K, V> {
63
50
{
64
51
if let Some ( root) = & self . root {
65
52
let root_node = root. node_as_ref ( ) ;
66
- let mut checker = SeriesChecker { previous : None } ;
67
- let mut internal_length = 0 ;
68
- let mut internal_kv_count = 0 ;
69
- let mut leaf_length = 0 ;
70
- root_node. visit_nodes_in_order ( |pos| match pos {
71
- Position :: Leaf ( node) => {
72
- let is_root = root_node. height ( ) == 0 ;
73
- let min_len = if is_root { 0 } else { node:: MIN_LEN } ;
74
- assert ! ( node. len( ) >= min_len, "{} < {}" , node. len( ) , min_len) ;
75
-
76
- for idx in 0 ..node. len ( ) {
77
- let key = * unsafe { node. key_at ( idx) } ;
78
- checker. is_ascending ( key) ;
79
- }
80
- leaf_length += node. len ( ) ;
81
- }
82
- Position :: Internal ( node) => {
83
- let is_root = root_node. height ( ) == node. height ( ) ;
84
- let min_len = if is_root { 1 } else { node:: MIN_LEN } ;
85
- assert ! ( node. len( ) >= min_len, "{} < {}" , node. len( ) , min_len) ;
86
-
87
- for idx in 0 ..=node. len ( ) {
88
- let edge = unsafe { node:: Handle :: new_edge ( node, idx) } ;
89
- assert ! ( edge. descend( ) . ascend( ) . ok( ) . unwrap( ) == edge) ;
90
- }
91
-
92
- internal_length += node. len ( ) ;
93
- }
94
- Position :: InternalKV ( kv) => {
95
- let key = * kv. into_kv ( ) . 0 ;
96
- checker. is_ascending ( key) ;
97
-
98
- internal_kv_count += 1 ;
99
- }
100
- } ) ;
101
- assert_eq ! ( internal_length, internal_kv_count) ;
102
- assert_eq ! ( root_node. calc_length( ) , internal_length + leaf_length) ;
103
- assert_eq ! ( self . length, internal_length + leaf_length) ;
53
+ assert ! ( root_node. ascend( ) . is_err( ) ) ;
54
+ root_node. assert_back_pointers ( ) ;
55
+ root_node. assert_ascending ( ) ;
56
+ assert_eq ! ( self . length, root_node. assert_and_add_lengths( ) ) ;
104
57
} else {
105
58
assert_eq ! ( self . length, 0 ) ;
106
59
}
@@ -116,28 +69,7 @@ impl<'a, K: 'a, V: 'a> BTreeMap<K, V> {
116
69
K : Debug ,
117
70
{
118
71
if let Some ( root) = self . root . as_ref ( ) {
119
- let mut result = String :: new ( ) ;
120
- let root_node = root. node_as_ref ( ) ;
121
- root_node. visit_nodes_in_order ( |pos| match pos {
122
- Position :: Leaf ( leaf) => {
123
- let depth = root_node. height ( ) ;
124
- let indent = " " . repeat ( depth) ;
125
- result += & format ! ( "\n {}" , indent) ;
126
- for idx in 0 ..leaf. len ( ) {
127
- if idx > 0 {
128
- result += ", " ;
129
- }
130
- result += & format ! ( "{:?}" , unsafe { leaf. key_at( idx) } ) ;
131
- }
132
- }
133
- Position :: Internal ( _) => { }
134
- Position :: InternalKV ( kv) => {
135
- let depth = root_node. height ( ) - kv. into_node ( ) . height ( ) ;
136
- let indent = " " . repeat ( depth) ;
137
- result += & format ! ( "\n {}{:?}" , indent, kv. into_kv( ) . 0 ) ;
138
- }
139
- } ) ;
140
- result
72
+ root. node_as_ref ( ) . dump_keys ( )
141
73
} else {
142
74
String :: from ( "not yet allocated" )
143
75
}
@@ -170,7 +102,6 @@ fn test_levels() {
170
102
let last_key = * map. last_key_value ( ) . unwrap ( ) . 0 ;
171
103
map. insert ( last_key + 1 , ( ) ) ;
172
104
}
173
- println ! ( "{}" , map. dump_keys( ) ) ;
174
105
map. check ( ) ;
175
106
// Structure:
176
107
// - 1 element in internal root node with 2 children
@@ -372,7 +303,7 @@ fn test_iter_rev() {
372
303
fn do_test_iter_mut_mutation < T > ( size : usize )
373
304
where
374
305
T : Copy + Debug + Ord + TryFrom < usize > ,
375
- <T as std :: convert :: TryFrom < usize > >:: Error : std :: fmt :: Debug ,
306
+ <T as TryFrom < usize > >:: Error : Debug ,
376
307
{
377
308
let zero = T :: try_from ( 0 ) . unwrap ( ) ;
378
309
let mut map: BTreeMap < T , T > = ( 0 ..size) . map ( |i| ( T :: try_from ( i) . unwrap ( ) , zero) ) . collect ( ) ;
@@ -857,7 +788,7 @@ mod test_drain_filter {
857
788
fn consuming_nothing ( ) {
858
789
let pairs = ( 0 ..3 ) . map ( |i| ( i, i) ) ;
859
790
let mut map: BTreeMap < _ , _ > = pairs. collect ( ) ;
860
- assert ! ( map. drain_filter( |_, _| false ) . eq( std :: iter:: empty( ) ) ) ;
791
+ assert ! ( map. drain_filter( |_, _| false ) . eq( iter:: empty( ) ) ) ;
861
792
map. check ( ) ;
862
793
}
863
794
@@ -878,7 +809,7 @@ mod test_drain_filter {
878
809
* v += 6 ;
879
810
false
880
811
} )
881
- . eq( std :: iter:: empty( ) )
812
+ . eq( iter:: empty( ) )
882
813
) ;
883
814
assert ! ( map. keys( ) . copied( ) . eq( 0 ..3 ) ) ;
884
815
assert ! ( map. values( ) . copied( ) . eq( 6 ..9 ) ) ;
0 commit comments