From 1aaeda1e1eda1ff5a78f92a5e60e93319174528e Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Tue, 15 Jan 2013 09:58:52 -0500 Subject: [PATCH] add scaffolding for symmetric_difference/union --- src/libstd/treemap.rs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/libstd/treemap.rs b/src/libstd/treemap.rs index 44345bdd853..9ebb760358b 100644 --- a/src/libstd/treemap.rs +++ b/src/libstd/treemap.rs @@ -229,13 +229,13 @@ impl TreeSet { /// Return true if the set has no elements in common with `other`. /// This is equivalent to checking for an empty intersection. pure fn is_disjoint(&self, other: &TreeSet) -> bool { - // FIXME: this is a naive O(n*log(m)) implementation, could be O(n) + // FIXME: this is a naive O(n*log(m)) implementation, could be O(n + m) !iter::any(self, |x| other.contains(x)) } /// Check of the set is a subset of another pure fn is_subset(&self, other: &TreeSet) -> bool { - // FIXME: this is a naive O(n*log(m)) implementation, could be O(n) + // FIXME: this is a naive O(n*log(m)) implementation, could be O(n + m) !iter::any(self, |x| !other.contains(x)) } @@ -278,14 +278,21 @@ impl TreeSet { } /// Visit the values (in-order) representing the symmetric difference - pure fn symmetric_difference(&self, _other: &TreeSet, + pure fn symmetric_difference(&self, other: &TreeSet, _f: fn(&T) -> bool) { + unsafe { // purity workaround + let mut x = self.map.iter(); + let mut y = other.map.iter(); + + let mut a = x.next(); + let mut b = y.next(); + } fail ~"not yet implemented" } /// Visit the values (in-order) representing the intersection pure fn intersection(&self, other: &TreeSet, f: fn(&T) -> bool) { - // FIXME: this is a naive O(n*log(m)) implementation, could be O(n) + // FIXME: this is a naive O(n*log(m)) implementation, could be O(n + m) for self.each |x| { if other.contains(x) { if !f(x) { break } @@ -294,7 +301,14 @@ impl TreeSet { } /// Visit the values (in-order) representing the union - pure fn union(&self, _other: &TreeSet, _f: fn(&T) -> bool) { + pure fn union(&self, other: &TreeSet, _f: fn(&T) -> bool) { + unsafe { // purity workaround + let mut x = self.map.iter(); + let mut y = other.map.iter(); + + let mut a = x.next(); + let mut b = y.next(); + } fail ~"not yet implemented" } }