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 ff95b4306541a488d0bb5daf90f5df34278f0aa6..5d580695a25fe60fa9f81df2c433d83d22b8afe9 100644 |
| --- a/sdk/lib/collection/hash_set.dart |
| +++ b/sdk/lib/collection/hash_set.dart |
| @@ -5,20 +5,21 @@ |
| part of dart.collection; |
| /** Common parts of [HashSet] and [LinkedHashSet] implementations. */ |
| -abstract class _HashSetBase<E> extends IterableBase<E> implements Set<E> { |
| +abstract class _HashSetBase<E> extends SetBase<E> { |
| - // Set. |
| - bool containsAll(Iterable<Object> other) { |
| - for (Object object in other) { |
| - if (!this.contains(object)) return false; |
| + Set<E> difference(Set<Object> other) { |
| + // Start from an empty set and add elements, |
| + // unlike SetBase which starts from toSet() and removes elements. |
|
Søren Gjesse
2014/05/22 09:25:52
Move the comment to before the method, and say thi
Lasse Reichstein Nielsen
2014/05/22 09:41:37
Done.
|
| + Set<E> result = _newSet(); |
| + for (var element in this) { |
| + if (!other.contains(element)) result.add(element); |
| } |
| - return true; |
| + return result; |
| } |
| - /** Create a new Set of the same type as this. */ |
| - HashSet<E> _newSet(); |
| - |
| Set<E> intersection(Set<Object> other) { |
| + // Start from an empty set and add elements, |
| + // unlike SetBase which starts from toSet() and removes elements. |
| Set<E> result = _newSet(); |
| for (var element in this) { |
| if (other.contains(element)) result.add(element); |
| @@ -26,38 +27,9 @@ abstract class _HashSetBase<E> extends IterableBase<E> implements Set<E> { |
| return result; |
| } |
| - Set<E> union(Set<E> other) { |
| - return _newSet()..addAll(this)..addAll(other); |
| - } |
| - |
| - Set<E> difference(Set<E> other) { |
| - HashSet<E> result = _newSet(); |
| - for (E element in this) { |
| - if (!other.contains(element)) result.add(element); |
| - } |
| - return result; |
| - } |
| - |
| - void _retainAll(Iterable objectsToRetain, bool isValidKey(Object o)) { |
| - // TODO(lrn): Consider optimizing table based versions by |
| - // building a new table of the entries to retain. |
| - Set retainSet = _newSet(); |
| - for (Object o in objectsToRetain) { |
| - if (isValidKey(o)) { |
| - retainSet.add(o); |
| - } |
| - } |
| - retainWhere(retainSet.contains); |
| - } |
| - |
| - List<E> toList({bool growable: true}) { |
| - List<E> result = growable ? (new List<E>()..length = this.length) |
| - : new List<E>(this.length); |
| - int i = 0; |
| - for (E element in this) result[i++] = element; |
| - return result; |
| - } |
| + Set<E> _newSet(); |
| + // Subclasses can optimize this further. |
| Set<E> toSet() => _newSet()..addAll(this); |
| String toString() => IterableMixinWorkaround.toStringIterable(this, '{', '}'); |