diff options
| author | Daniel Micay <danielmicay@gmail.com> | 2013-01-29 17:04:25 -0500 |
|---|---|---|
| committer | Daniel Micay <danielmicay@gmail.com> | 2013-01-29 21:30:55 -0500 |
| commit | 42cafcee2c740c6d2a85018a947b78338d2afa8e (patch) | |
| tree | 5c106f66dd90edb755290c22f9cad8623e20a1d0 /src/libstd | |
| parent | bfa9c9a00f0a301a5e936ae14c6a95e98f3bf5ee (diff) | |
add is_disjoint to the Set trait
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/treemap.rs | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/src/libstd/treemap.rs b/src/libstd/treemap.rs index ece120bb647..b1c22f86c96 100644 --- a/src/libstd/treemap.rs +++ b/src/libstd/treemap.rs @@ -292,6 +292,33 @@ impl <T: Ord> TreeSet<T>: Set<T> { /// present in the set. fn remove(&mut self, value: &T) -> bool { self.map.remove(value) } + /// 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<T>) -> bool { + let mut x = self.iter(); + let mut y = other.iter(); + unsafe { // purity workaround + x = x.next(); + y = y.next(); + let mut a = x.get(); + let mut b = y.get(); + while a.is_some() && b.is_some() { + let a1 = a.unwrap(); + let b1 = b.unwrap(); + if a1 < b1 { + x = x.next(); + a = x.get(); + } else if b1 < a1 { + y = y.next(); + b = y.get(); + } else { + return false; + } + } + } + true + } + /// Return true if the set is a subset of another pure fn is_subset(&self, other: &TreeSet<T>) -> bool { other.is_superset(self) @@ -345,33 +372,6 @@ impl <T: Ord> TreeSet<T> { TreeSetIterator{iter: self.map.iter()} } - /// 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<T>) -> bool { - let mut x = self.iter(); - let mut y = other.iter(); - unsafe { // purity workaround - x = x.next(); - y = y.next(); - let mut a = x.get(); - let mut b = y.get(); - while a.is_some() && b.is_some() { - let a1 = a.unwrap(); - let b1 = b.unwrap(); - if a1 < b1 { - x = x.next(); - a = x.get(); - } else if b1 < a1 { - y = y.next(); - b = y.get(); - } else { - return false; - } - } - } - true - } - /// Visit the values (in-order) representing the difference pure fn difference(&self, other: &TreeSet<T>, f: fn(&T) -> bool) { let mut x = self.iter(); |
