Chromium Code Reviews| Index: sdk/lib/collection/linked_hash_set.dart |
| diff --git a/sdk/lib/collection/linked_hash_set.dart b/sdk/lib/collection/linked_hash_set.dart |
| index 7fc0653b22751e170c38caba8703b2e4204eba85..17c41c07d0574f87cf2f379b0b99c119767bfb5e 100644 |
| --- a/sdk/lib/collection/linked_hash_set.dart |
| +++ b/sdk/lib/collection/linked_hash_set.dart |
| @@ -128,27 +128,52 @@ class LinkedHashSet<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
ditto. isSubsetOf(other) => other.containsAll(this
floitsch
2013/03/12 16:25:00
move all these methods to IterableMixinWorkaround?
Lasse Reichstein Nielsen
2013/03/13 13:01:42
Done.
|
| + 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 LinkedHashSet<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 LinkedHashSet<E>(); |
| + result.addAll(this); |
| + result.addAll(other); |
| + return result; |
| + } |
| + |
| + Set<E> difference(Set<E> other) { |
| + Set<E> result = new LinkedHashSet<E>(); |
| + for (E element in this) { |
| + if (!other.contains(element)) { |
| result.add(element); |
| } |
| } |