@@ -155,12 +155,6 @@ impl<T: fmt::Debug> fmt::Debug for SymmetricDifference<'_, T> {
155
155
}
156
156
}
157
157
158
- #[ derive( Debug ) ]
159
- enum IntersectionOther < ' a , T > {
160
- ITER ( Peekable < Iter < ' a , T > > ) ,
161
- SET ( & ' a BTreeSet < T > ) ,
162
- }
163
-
164
158
/// Whether the sizes of two sets are roughly the same order of magnitude.
165
159
///
166
160
/// If they are, or if either set is empty, then their intersection
@@ -190,6 +184,12 @@ pub struct Intersection<'a, T: 'a> {
190
184
b : IntersectionOther < ' a , T > ,
191
185
}
192
186
187
+ #[ derive( Debug ) ]
188
+ enum IntersectionOther < ' a , T > {
189
+ Stitch ( Peekable < Iter < ' a , T > > ) ,
190
+ Search ( & ' a BTreeSet < T > ) ,
191
+ }
192
+
193
193
#[ stable( feature = "collection_debug" , since = "1.17.0" ) ]
194
194
impl < T : fmt:: Debug > fmt:: Debug for Intersection < ' _ , T > {
195
195
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
@@ -351,17 +351,17 @@ impl<T: Ord> BTreeSet<T> {
351
351
if are_proportionate_for_intersection ( self . len ( ) , other. len ( ) ) {
352
352
Intersection {
353
353
a : self . iter ( ) . peekable ( ) ,
354
- b : IntersectionOther :: ITER ( other. iter ( ) . peekable ( ) ) ,
354
+ b : IntersectionOther :: Stitch ( other. iter ( ) . peekable ( ) ) ,
355
355
}
356
356
} else if self . len ( ) <= other. len ( ) {
357
357
Intersection {
358
358
a : self . iter ( ) . peekable ( ) ,
359
- b : IntersectionOther :: SET ( & other) ,
359
+ b : IntersectionOther :: Search ( & other) ,
360
360
}
361
361
} else {
362
362
Intersection {
363
363
a : other. iter ( ) . peekable ( ) ,
364
- b : IntersectionOther :: SET ( & self ) ,
364
+ b : IntersectionOther :: Search ( & self ) ,
365
365
}
366
366
}
367
367
}
@@ -1106,8 +1106,8 @@ impl<T: Ord> FusedIterator for SymmetricDifference<'_, T> {}
1106
1106
impl < ' a , T > Clone for IntersectionOther < ' a , T > {
1107
1107
fn clone ( & self ) -> IntersectionOther < ' a , T > {
1108
1108
match self {
1109
- IntersectionOther :: ITER ( ref iter) => IntersectionOther :: ITER ( iter. clone ( ) ) ,
1110
- IntersectionOther :: SET ( set) => IntersectionOther :: SET ( set) ,
1109
+ IntersectionOther :: Stitch ( ref iter) => IntersectionOther :: Stitch ( iter. clone ( ) ) ,
1110
+ IntersectionOther :: Search ( set) => IntersectionOther :: Search ( set) ,
1111
1111
}
1112
1112
}
1113
1113
}
@@ -1126,7 +1126,7 @@ impl<'a, T: Ord> Iterator for Intersection<'a, T> {
1126
1126
1127
1127
fn next ( & mut self ) -> Option < & ' a T > {
1128
1128
match self . b {
1129
- IntersectionOther :: ITER ( ref mut self_b) => loop {
1129
+ IntersectionOther :: Stitch ( ref mut self_b) => loop {
1130
1130
match Ord :: cmp ( self . a . peek ( ) ?, self_b. peek ( ) ?) {
1131
1131
Less => {
1132
1132
self . a . next ( ) ;
@@ -1140,23 +1140,19 @@ impl<'a, T: Ord> Iterator for Intersection<'a, T> {
1140
1140
}
1141
1141
}
1142
1142
}
1143
- IntersectionOther :: SET ( set) => loop {
1144
- match self . a . next ( ) {
1145
- None => return None ,
1146
- Some ( e) => {
1147
- if set. contains ( & e) {
1148
- return Some ( e) ;
1149
- }
1150
- }
1143
+ IntersectionOther :: Search ( set) => loop {
1144
+ let e = self . a . next ( ) ?;
1145
+ if set. contains ( & e) {
1146
+ return Some ( e) ;
1151
1147
}
1152
1148
}
1153
1149
}
1154
1150
}
1155
1151
1156
1152
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
1157
1153
let b_len = match self . b {
1158
- IntersectionOther :: ITER ( ref iter) => iter. len ( ) ,
1159
- IntersectionOther :: SET ( set) => set. len ( ) ,
1154
+ IntersectionOther :: Stitch ( ref iter) => iter. len ( ) ,
1155
+ IntersectionOther :: Search ( set) => set. len ( ) ,
1160
1156
} ;
1161
1157
( 0 , Some ( min ( self . a . len ( ) , b_len) ) )
1162
1158
}
0 commit comments