3
3
4
4
use core:: borrow:: Borrow ;
5
5
use core:: cmp:: Ordering :: { self , Less , Greater , Equal } ;
6
- use core:: cmp:: max;
6
+ use core:: cmp:: { max, min } ;
7
7
use core:: fmt:: { self , Debug } ;
8
8
use core:: iter:: { Peekable , FromIterator , FusedIterator } ;
9
9
use core:: ops:: { BitOr , BitAnd , BitXor , Sub , RangeBounds } ;
@@ -187,8 +187,8 @@ pub struct Intersection<'a, T: 'a> {
187
187
}
188
188
enum IntersectionInner < ' a , T : ' a > {
189
189
Stitch {
190
- small_iter : Iter < ' a , T > , // for size_hint, should be the smaller of the sets
191
- other_iter : Iter < ' a , T > ,
190
+ a : Iter < ' a , T > ,
191
+ b : Iter < ' a , T > ,
192
192
} ,
193
193
Search {
194
194
small_iter : Iter < ' a , T > ,
@@ -201,12 +201,12 @@ impl<T: fmt::Debug> fmt::Debug for Intersection<'_, T> {
201
201
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
202
202
match & self . inner {
203
203
IntersectionInner :: Stitch {
204
- small_iter ,
205
- other_iter ,
204
+ a ,
205
+ b ,
206
206
} => f
207
207
. debug_tuple ( "Intersection" )
208
- . field ( & small_iter )
209
- . field ( & other_iter )
208
+ . field ( & a )
209
+ . field ( & b )
210
210
. finish ( ) ,
211
211
IntersectionInner :: Search {
212
212
small_iter,
@@ -397,8 +397,8 @@ impl<T: Ord> BTreeSet<T> {
397
397
// Iterate both sets jointly, spotting matches along the way.
398
398
Intersection {
399
399
inner : IntersectionInner :: Stitch {
400
- small_iter : small. iter ( ) ,
401
- other_iter : other. iter ( ) ,
400
+ a : small. iter ( ) ,
401
+ b : other. iter ( ) ,
402
402
} ,
403
403
}
404
404
} else {
@@ -1221,11 +1221,11 @@ impl<T> Clone for Intersection<'_, T> {
1221
1221
Intersection {
1222
1222
inner : match & self . inner {
1223
1223
IntersectionInner :: Stitch {
1224
- small_iter ,
1225
- other_iter ,
1224
+ a ,
1225
+ b ,
1226
1226
} => IntersectionInner :: Stitch {
1227
- small_iter : small_iter . clone ( ) ,
1228
- other_iter : other_iter . clone ( ) ,
1227
+ a : a . clone ( ) ,
1228
+ b : b . clone ( ) ,
1229
1229
} ,
1230
1230
IntersectionInner :: Search {
1231
1231
small_iter,
@@ -1245,16 +1245,16 @@ impl<'a, T: Ord> Iterator for Intersection<'a, T> {
1245
1245
fn next ( & mut self ) -> Option < & ' a T > {
1246
1246
match & mut self . inner {
1247
1247
IntersectionInner :: Stitch {
1248
- small_iter ,
1249
- other_iter ,
1248
+ a ,
1249
+ b ,
1250
1250
} => {
1251
- let mut small_next = small_iter . next ( ) ?;
1252
- let mut other_next = other_iter . next ( ) ?;
1251
+ let mut a_next = a . next ( ) ?;
1252
+ let mut b_next = b . next ( ) ?;
1253
1253
loop {
1254
- match Ord :: cmp ( small_next , other_next ) {
1255
- Less => small_next = small_iter . next ( ) ?,
1256
- Greater => other_next = other_iter . next ( ) ?,
1257
- Equal => return Some ( small_next ) ,
1254
+ match Ord :: cmp ( a_next , b_next ) {
1255
+ Less => a_next = a . next ( ) ?,
1256
+ Greater => b_next = b . next ( ) ?,
1257
+ Equal => return Some ( a_next ) ,
1258
1258
}
1259
1259
}
1260
1260
}
@@ -1272,7 +1272,7 @@ impl<'a, T: Ord> Iterator for Intersection<'a, T> {
1272
1272
1273
1273
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
1274
1274
let min_len = match & self . inner {
1275
- IntersectionInner :: Stitch { small_iter , .. } => small_iter . len ( ) ,
1275
+ IntersectionInner :: Stitch { a , b } => min ( a . len ( ) , b . len ( ) ) ,
1276
1276
IntersectionInner :: Search { small_iter, .. } => small_iter. len ( ) ,
1277
1277
} ;
1278
1278
( 0 , Some ( min_len) )
0 commit comments