Chromium Code Reviews| Index: sdk/lib/collection/hash_set.dart |
| diff --git a/sdk/lib/collection/hash_set.dart b/sdk/lib/collection/hash_set.dart |
| index 69080293a042a40849539d22dcd0c79410a73482..ea945bd68c16f2c16977d93cf3f7aec925756718 100644 |
| --- a/sdk/lib/collection/hash_set.dart |
| +++ b/sdk/lib/collection/hash_set.dart |
| @@ -86,27 +86,52 @@ class HashSet<E> extends Collection<E> implements Set<E> { |
| } |
| // Set. |
| - bool isSubsetOf(Collection<E> collection) { |
| - Set otherSet; |
| - if (collection is Set) { |
| - otherSet = collection; |
| - } else { |
| - otherSet = collection.toSet(); |
| + bool isSubsetOf(Set<E> other) { |
|
floitsch
2013/03/12 16:25:00
bool isSubsetOf(Set<E> other) => other.containsAll
Lasse Reichstein Nielsen
2013/03/13 13:01:42
The resason is the usual one: I don't want public,
|
| + if (length > other.length) return false; |
| + for (E element in this) { |
| + if (!other.contains(element)) return false; |
| } |
| - return otherSet.containsAll(this); |
| + return true; |
| } |
| - bool containsAll(Collection<E> collection) { |
| - for (E element in collection) { |
| + bool containsAll(Set<E> other) { |
| + if (other.length > length) return false; |
| + for (E element in other) { |
| if (!this.contains(element)) return false; |
| } |
| return true; |
| } |
| - Set<E> intersection(Collection<E> other) { |
| + Set<E> intersection(Set<E> other) { |
| + Set<E> smaller; |
| + Set<E> larger; |
| + if (length < other.length) { |
| + smaller = this; |
| + larger = other; |
| + } else { |
| + smaller = other; |
| + larger = this; |
| + } |
| Set<E> result = new HashSet<E>(); |
| - for (E element in other) { |
| - if (this.contains(element)) { |
| + for (E element in smaller) { |
| + if (larger.contains(element)) { |
| + result.add(element); |
| + } |
| + } |
| + return result; |
| + } |
| + |
| + Set<E> union(Set<E> other) { |
| + Set<E> result = new HashSet<E>(); |
| + result.addAll(this); |
| + result.addAll(other); |
| + return result; |
| + } |
| + |
| + Set<E> difference(Set<E> other) { |
| + Set<E> result = new HashSet<E>(); |
| + for (E element in this) { |
| + if (!other.contains(element)) { |
| result.add(element); |
| } |
| } |