7
7
// You may not use this file except in accordance with one or both of these
8
8
// licenses.
9
9
10
- use lightning:: util:: indexed_map:: { IndexedMap , self } ;
11
- use std:: collections:: { BTreeMap , btree_map} ;
12
10
use lightning:: util:: hash_tables:: * ;
11
+ use lightning:: util:: indexed_map:: { self , IndexedMap } ;
12
+ use std:: collections:: { btree_map, BTreeMap } ;
13
13
14
14
use crate :: utils:: test_logger;
15
15
16
- use std:: ops:: { RangeBounds , Bound } ;
16
+ use std:: ops:: { Bound , RangeBounds } ;
17
17
18
18
struct ExclLowerInclUpper ( u8 , u8 ) ;
19
19
impl RangeBounds < u8 > for ExclLowerInclUpper {
20
- fn start_bound ( & self ) -> Bound < & u8 > { Bound :: Excluded ( & self . 0 ) }
21
- fn end_bound ( & self ) -> Bound < & u8 > { Bound :: Included ( & self . 1 ) }
20
+ fn start_bound ( & self ) -> Bound < & u8 > {
21
+ Bound :: Excluded ( & self . 0 )
22
+ }
23
+ fn end_bound ( & self ) -> Bound < & u8 > {
24
+ Bound :: Included ( & self . 1 )
25
+ }
22
26
}
23
27
struct ExclLowerExclUpper ( u8 , u8 ) ;
24
28
impl RangeBounds < u8 > for ExclLowerExclUpper {
25
- fn start_bound ( & self ) -> Bound < & u8 > { Bound :: Excluded ( & self . 0 ) }
26
- fn end_bound ( & self ) -> Bound < & u8 > { Bound :: Excluded ( & self . 1 ) }
29
+ fn start_bound ( & self ) -> Bound < & u8 > {
30
+ Bound :: Excluded ( & self . 0 )
31
+ }
32
+ fn end_bound ( & self ) -> Bound < & u8 > {
33
+ Bound :: Excluded ( & self . 1 )
34
+ }
27
35
}
28
36
29
37
fn check_eq ( btree : & BTreeMap < u8 , u8 > , mut indexed : IndexedMap < u8 , u8 > ) {
@@ -46,36 +54,44 @@ fn check_eq(btree: &BTreeMap<u8, u8>, mut indexed: IndexedMap<u8, u8>) {
46
54
if let indexed_map:: Entry :: Occupied ( mut io) = indexed_entry {
47
55
assert_eq ! ( bo. get( ) , io. get( ) ) ;
48
56
assert_eq ! ( bo. get_mut( ) , io. get_mut( ) ) ;
49
- } else { panic ! ( ) ; }
57
+ } else {
58
+ panic ! ( ) ;
59
+ }
50
60
} ,
51
61
btree_map:: Entry :: Vacant ( _) => {
52
62
if let indexed_map:: Entry :: Vacant ( _) = indexed_entry {
53
- } else { panic ! ( ) ; }
54
- }
63
+ } else {
64
+ panic ! ( ) ;
65
+ }
66
+ } ,
55
67
}
56
68
}
57
69
58
70
const STRIDE : u8 = 16 ;
59
71
for range_type in 0 ..4 {
60
- for k in 0 ..=255 / STRIDE {
72
+ for k in 0 ..=255 / STRIDE {
61
73
let lower_bound = k * STRIDE ;
62
74
let upper_bound = lower_bound + ( STRIDE - 1 ) ;
63
- macro_rules! range { ( $map: expr) => {
64
- match range_type {
65
- 0 => $map. range( lower_bound..upper_bound) ,
66
- 1 => $map. range( lower_bound..=upper_bound) ,
67
- 2 => $map. range( ExclLowerInclUpper ( lower_bound, upper_bound) ) ,
68
- 3 => $map. range( ExclLowerExclUpper ( lower_bound, upper_bound) ) ,
69
- _ => unreachable!( ) ,
70
- }
71
- } }
75
+ macro_rules! range {
76
+ ( $map: expr) => {
77
+ match range_type {
78
+ 0 => $map. range( lower_bound..upper_bound) ,
79
+ 1 => $map. range( lower_bound..=upper_bound) ,
80
+ 2 => $map. range( ExclLowerInclUpper ( lower_bound, upper_bound) ) ,
81
+ 3 => $map. range( ExclLowerExclUpper ( lower_bound, upper_bound) ) ,
82
+ _ => unreachable!( ) ,
83
+ }
84
+ } ;
85
+ }
72
86
let mut btree_iter = range ! ( btree) ;
73
87
let mut indexed_iter = range ! ( indexed) ;
74
88
loop {
75
89
let b_v = btree_iter. next ( ) ;
76
90
let i_v = indexed_iter. next ( ) ;
77
91
assert_eq ! ( b_v, i_v) ;
78
- if b_v. is_none ( ) { break ; }
92
+ if b_v. is_none ( ) {
93
+ break ;
94
+ }
79
95
}
80
96
}
81
97
}
@@ -104,7 +120,9 @@ fn check_eq(btree: &BTreeMap<u8, u8>, mut indexed: IndexedMap<u8, u8>) {
104
120
105
121
#[ inline]
106
122
pub fn do_test ( data : & [ u8 ] ) {
107
- if data. len ( ) % 2 != 0 { return ; }
123
+ if data. len ( ) % 2 != 0 {
124
+ return ;
125
+ }
108
126
let mut btree = BTreeMap :: new ( ) ;
109
127
let mut indexed = IndexedMap :: new ( ) ;
110
128
@@ -138,13 +156,17 @@ pub fn do_test(data: &[u8]) {
138
156
} else {
139
157
assert_eq ! ( bo. remove_entry( ) , io. remove_entry( ) ) ;
140
158
}
141
- } else { panic ! ( ) ; }
159
+ } else {
160
+ panic ! ( ) ;
161
+ }
142
162
} ,
143
163
btree_map:: Entry :: Vacant ( bv) => {
144
164
if let indexed_map:: Entry :: Vacant ( iv) = indexed. entry ( k) {
145
165
bv. insert ( k) ;
146
166
iv. insert ( k) ;
147
- } else { panic ! ( ) ; }
167
+ } else {
168
+ panic ! ( ) ;
169
+ }
148
170
} ,
149
171
}
150
172
}
0 commit comments