Skip to content

Commit 2540cf0

Browse files
author
Jorge Aparicio
committed
---
yaml --- r: 163256 b: refs/heads/snap-stage3 c: c3fe710 h: refs/heads/master v: v3
1 parent 584079f commit 2540cf0

File tree

2 files changed

+23
-15
lines changed
  • branches/snap-stage3/src/libstd/collections/hash

2 files changed

+23
-15
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 9146a919b616e39e528e4d7100d16eef52f1f852
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 4f6f6af281b47a95576b648ac924d79835f16db2
4+
refs/heads/snap-stage3: c3fe7105ba4362bce7f795f4502163bcec039d74
55
refs/heads/try: 20cbbffeefc1f35e2ea63afce7b42fbd79611d42
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d

branches/snap-stage3/src/libstd/collections/hash/set.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use fmt;
1919
use hash::{Hash, Hasher, RandomSipHasher};
2020
use iter::{Iterator, IteratorExt, FromIterator, FilterMap, Chain, Repeat, Zip, Extend, repeat};
2121
use iter;
22-
use option::Option::{Some, None};
22+
use option::Option::{Some, None, mod};
2323
use result::Result::{Ok, Err};
2424

2525
use super::map::{HashMap, Entries, MoveEntries, INITIAL_CAPACITY};
@@ -306,10 +306,13 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> {
306306
/// ```
307307
#[unstable = "matches collection reform specification, waiting for dust to settle"]
308308
pub fn difference<'a>(&'a self, other: &'a HashSet<T, H>) -> SetAlgebraItems<'a, T, H> {
309-
repeat(other).zip(self.iter())
310-
.filter_map(|(other, elt)| {
311-
if !other.contains(elt) { Some(elt) } else { None }
312-
})
309+
fn filter<'a, T, S, H>((other, elt): (&HashSet<T, H>, &'a T)) -> Option<&'a T> where
310+
T: Eq + Hash<S>, H: Hasher<S>
311+
{
312+
if !other.contains(elt) { Some(elt) } else { None }
313+
}
314+
315+
repeat(other).zip(self.iter()).filter_map(filter)
313316
}
314317

315318
/// Visit the values representing the symmetric difference.
@@ -356,12 +359,14 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> {
356359
/// assert_eq!(diff, [2i, 3].iter().map(|&x| x).collect());
357360
/// ```
358361
#[unstable = "matches collection reform specification, waiting for dust to settle"]
359-
pub fn intersection<'a>(&'a self, other: &'a HashSet<T, H>)
360-
-> SetAlgebraItems<'a, T, H> {
361-
repeat(other).zip(self.iter())
362-
.filter_map(|(other, elt)| {
363-
if other.contains(elt) { Some(elt) } else { None }
364-
})
362+
pub fn intersection<'a>(&'a self, other: &'a HashSet<T, H>) -> SetAlgebraItems<'a, T, H> {
363+
fn filter<'a, T, S, H>((other, elt): (&HashSet<T, H>, &'a T)) -> Option<&'a T> where
364+
T: Eq + Hash<S>, H: Hasher<S>
365+
{
366+
if other.contains(elt) { Some(elt) } else { None }
367+
}
368+
369+
repeat(other).zip(self.iter()).filter_map(filter)
365370
}
366371

367372
/// Visit the values representing the union.
@@ -621,9 +626,12 @@ pub type SetMoveItems<K> = iter::Map<(K, ()), K, MoveEntries<K, ()>, fn((K, ()))
621626
// `Repeat` is used to feed the filter closure an explicit capture
622627
// of a reference to the other set
623628
/// Set operations iterator
624-
pub type SetAlgebraItems<'a, T, H> =
625-
FilterMap<'static, (&'a HashSet<T, H>, &'a T), &'a T,
626-
Zip<Repeat<&'a HashSet<T, H>>, SetItems<'a, T>>>;
629+
pub type SetAlgebraItems<'a, T, H> = FilterMap<
630+
(&'a HashSet<T, H>, &'a T),
631+
&'a T,
632+
Zip<Repeat<&'a HashSet<T, H>>, SetItems<'a, T>>,
633+
for<'b> fn((&HashSet<T, H>, &'b T)) -> Option<&'b T>,
634+
>;
627635

628636
#[cfg(test)]
629637
mod test_set {

0 commit comments

Comments
 (0)