Skip to content

Commit 0186d90

Browse files
committed
renamed enum variants, moved struct declaration down, condensed Intersection.next
1 parent f536f7a commit 0186d90

File tree

1 file changed

+18
-22
lines changed
  • src/liballoc/collections/btree

1 file changed

+18
-22
lines changed

src/liballoc/collections/btree/set.rs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,6 @@ impl<T: fmt::Debug> fmt::Debug for SymmetricDifference<'_, T> {
155155
}
156156
}
157157

158-
#[derive(Debug)]
159-
enum IntersectionOther<'a, T> {
160-
ITER(Peekable<Iter<'a, T>>),
161-
SET(&'a BTreeSet<T>),
162-
}
163-
164158
/// Whether the sizes of two sets are roughly the same order of magnitude.
165159
///
166160
/// If they are, or if either set is empty, then their intersection
@@ -190,6 +184,12 @@ pub struct Intersection<'a, T: 'a> {
190184
b: IntersectionOther<'a, T>,
191185
}
192186

187+
#[derive(Debug)]
188+
enum IntersectionOther<'a, T> {
189+
Stitch(Peekable<Iter<'a, T>>),
190+
Search(&'a BTreeSet<T>),
191+
}
192+
193193
#[stable(feature = "collection_debug", since = "1.17.0")]
194194
impl<T: fmt::Debug> fmt::Debug for Intersection<'_, T> {
195195
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -351,17 +351,17 @@ impl<T: Ord> BTreeSet<T> {
351351
if are_proportionate_for_intersection(self.len(), other.len()) {
352352
Intersection {
353353
a: self.iter().peekable(),
354-
b: IntersectionOther::ITER(other.iter().peekable()),
354+
b: IntersectionOther::Stitch(other.iter().peekable()),
355355
}
356356
} else if self.len() <= other.len() {
357357
Intersection {
358358
a: self.iter().peekable(),
359-
b: IntersectionOther::SET(&other),
359+
b: IntersectionOther::Search(&other),
360360
}
361361
} else {
362362
Intersection {
363363
a: other.iter().peekable(),
364-
b: IntersectionOther::SET(&self),
364+
b: IntersectionOther::Search(&self),
365365
}
366366
}
367367
}
@@ -1106,8 +1106,8 @@ impl<T: Ord> FusedIterator for SymmetricDifference<'_, T> {}
11061106
impl<'a, T> Clone for IntersectionOther<'a, T> {
11071107
fn clone(&self) -> IntersectionOther<'a, T> {
11081108
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),
11111111
}
11121112
}
11131113
}
@@ -1126,7 +1126,7 @@ impl<'a, T: Ord> Iterator for Intersection<'a, T> {
11261126

11271127
fn next(&mut self) -> Option<&'a T> {
11281128
match self.b {
1129-
IntersectionOther::ITER(ref mut self_b) => loop {
1129+
IntersectionOther::Stitch(ref mut self_b) => loop {
11301130
match Ord::cmp(self.a.peek()?, self_b.peek()?) {
11311131
Less => {
11321132
self.a.next();
@@ -1140,23 +1140,19 @@ impl<'a, T: Ord> Iterator for Intersection<'a, T> {
11401140
}
11411141
}
11421142
}
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);
11511147
}
11521148
}
11531149
}
11541150
}
11551151

11561152
fn size_hint(&self) -> (usize, Option<usize>) {
11571153
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(),
11601156
};
11611157
(0, Some(min(self.a.len(), b_len)))
11621158
}

0 commit comments

Comments
 (0)