Skip to content

Commit 1aaeda1

Browse files
thestingergraydon
authored andcommitted
add scaffolding for symmetric_difference/union
1 parent 90b111f commit 1aaeda1

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/libstd/treemap.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,13 @@ impl <T: Ord> TreeSet<T> {
229229
/// Return true if the set has no elements in common with `other`.
230230
/// This is equivalent to checking for an empty intersection.
231231
pure fn is_disjoint(&self, other: &TreeSet<T>) -> bool {
232-
// FIXME: this is a naive O(n*log(m)) implementation, could be O(n)
232+
// FIXME: this is a naive O(n*log(m)) implementation, could be O(n + m)
233233
!iter::any(self, |x| other.contains(x))
234234
}
235235

236236
/// Check of the set is a subset of another
237237
pure fn is_subset(&self, other: &TreeSet<T>) -> bool {
238-
// FIXME: this is a naive O(n*log(m)) implementation, could be O(n)
238+
// FIXME: this is a naive O(n*log(m)) implementation, could be O(n + m)
239239
!iter::any(self, |x| !other.contains(x))
240240
}
241241

@@ -278,14 +278,21 @@ impl <T: Ord> TreeSet<T> {
278278
}
279279

280280
/// Visit the values (in-order) representing the symmetric difference
281-
pure fn symmetric_difference(&self, _other: &TreeSet<T>,
281+
pure fn symmetric_difference(&self, other: &TreeSet<T>,
282282
_f: fn(&T) -> bool) {
283+
unsafe { // purity workaround
284+
let mut x = self.map.iter();
285+
let mut y = other.map.iter();
286+
287+
let mut a = x.next();
288+
let mut b = y.next();
289+
}
283290
fail ~"not yet implemented"
284291
}
285292

286293
/// Visit the values (in-order) representing the intersection
287294
pure fn intersection(&self, other: &TreeSet<T>, f: fn(&T) -> bool) {
288-
// FIXME: this is a naive O(n*log(m)) implementation, could be O(n)
295+
// FIXME: this is a naive O(n*log(m)) implementation, could be O(n + m)
289296
for self.each |x| {
290297
if other.contains(x) {
291298
if !f(x) { break }
@@ -294,7 +301,14 @@ impl <T: Ord> TreeSet<T> {
294301
}
295302

296303
/// Visit the values (in-order) representing the union
297-
pure fn union(&self, _other: &TreeSet<T>, _f: fn(&T) -> bool) {
304+
pure fn union(&self, other: &TreeSet<T>, _f: fn(&T) -> bool) {
305+
unsafe { // purity workaround
306+
let mut x = self.map.iter();
307+
let mut y = other.map.iter();
308+
309+
let mut a = x.next();
310+
let mut b = y.next();
311+
}
298312
fail ~"not yet implemented"
299313
}
300314
}

0 commit comments

Comments
 (0)