Skip to content

Commit 150d162

Browse files
thestingergraydon
authored andcommitted
---
yaml --- r: 52347 b: refs/heads/dist-snap c: a73f4b1 h: refs/heads/master i: 52345: e483990 52343: df153ef v: v3
1 parent ba325fb commit 150d162

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
99
refs/heads/incoming: 44d4d6de762f3f9aae1fedcf454c66b79b3ad58d
10-
refs/heads/dist-snap: d44084e10084c1f442f8eb8932590c252eb6df85
10+
refs/heads/dist-snap: a73f4b1baa3533956582ec9892cc4d1780e45ed0
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1313
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/libstd/treemap.rs

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,15 +279,45 @@ impl <T: Ord> TreeSet<T> {
279279

280280
/// Visit the values (in-order) representing the symmetric difference
281281
pure fn symmetric_difference(&self, other: &TreeSet<T>,
282-
_f: fn(&T) -> bool) {
282+
f: fn(&T) -> bool) {
283283
unsafe { // purity workaround
284284
let mut x = self.map.iter();
285285
let mut y = other.map.iter();
286286

287287
let mut a = x.next();
288288
let mut b = y.next();
289+
290+
while a.is_some() {
291+
if b.is_none() {
292+
while a.is_some() {
293+
let (a1, _) = a.unwrap();
294+
if !f(a1) { return }
295+
a = x.next();
296+
}
297+
return
298+
}
299+
300+
let (a1, _) = a.unwrap();
301+
let (b1, _) = b.unwrap();
302+
303+
if a1 < b1 {
304+
if !f(a1) { return }
305+
a = x.next();
306+
} else {
307+
if b1 < a1 {
308+
if !f(b1) { return }
309+
} else {
310+
a = x.next();
311+
}
312+
b = y.next();
313+
}
314+
}
315+
while b.is_some() {
316+
let (b1, _) = b.unwrap();
317+
if !f(b1) { return }
318+
b = y.next();
319+
}
289320
}
290-
fail ~"not yet implemented"
291321
}
292322

293323
/// Visit the values (in-order) representing the intersection
@@ -895,6 +925,32 @@ mod test_set {
895925
assert i == expected.len();
896926
}
897927

928+
#[test]
929+
fn test_symmetric_difference() {
930+
let mut a = TreeSet::new();
931+
let mut b = TreeSet::new();
932+
933+
assert a.insert(1);
934+
assert a.insert(3);
935+
assert a.insert(5);
936+
assert a.insert(9);
937+
assert a.insert(11);
938+
939+
assert b.insert(-2);
940+
assert b.insert(3);
941+
assert b.insert(9);
942+
assert b.insert(14);
943+
assert b.insert(22);
944+
945+
let mut i = 0;
946+
let expected = [-2, 1, 5, 11, 14, 22];
947+
for a.symmetric_difference(&b) |x| {
948+
assert *x == expected[i];
949+
i += 1
950+
}
951+
assert i == expected.len();
952+
}
953+
898954
#[test]
899955
fn test_union() {
900956
let mut a = TreeSet::new();

0 commit comments

Comments
 (0)