Skip to content

Commit af97f61

Browse files
thestingergraydon
authored andcommitted
---
yaml --- r: 42465 b: refs/heads/try c: a73f4b1 h: refs/heads/master i: 42463: dca9d33 v: v3
1 parent 61b913f commit af97f61

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
@@ -2,7 +2,7 @@
22
refs/heads/master: 19dfec2aaf746535de1521f68421f9980dbf25de
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 2f46b763da2c098913884f101b6d71d69af41b49
5-
refs/heads/try: d44084e10084c1f442f8eb8932590c252eb6df85
5+
refs/heads/try: a73f4b1baa3533956582ec9892cc4d1780e45ed0
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278

branches/try/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)