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 ca32220cf7dcf6aafabd289480b6f829ef174e03..c578e64d5a341f4c4cf90a33a15d399aec48ff9e 100644 |
| --- a/sdk/lib/collection/hash_set.dart |
| +++ b/sdk/lib/collection/hash_set.dart |
| @@ -4,7 +4,7 @@ |
| part of dart.collection; |
| -class HashSet<E> extends Collection<E> implements Set<E> { |
| +class HashSet<E> extends Collection<E> with _SetMixin<E> implements Set<E> { |
|
floitsch
2013/04/05 12:38:17
I would prefer a common super-class (_SetBase ?) i
|
| static const int _INITIAL_CAPACITY = 8; |
| final _HashTable<E> _table; |
| @@ -51,10 +51,6 @@ class HashSet<E> extends Collection<E> implements Set<E> { |
| } |
| } |
| - void retainAll(Iterable objectsToRetain) { |
| - IterableMixinWorkaround.retainAll(this, objectsToRetain); |
| - } |
| - |
| void _filterWhere(bool test(E element), bool removeMatching) { |
| int entrySize = _table._entrySize; |
| int length = _table._table.length; |
| @@ -85,6 +81,15 @@ class HashSet<E> extends Collection<E> implements Set<E> { |
| _table._clear(); |
| } |
| + Set<E> _newSet() => new HashSet<E>(); |
| + |
| + String toString() => Collections.collectionToString(this); |
|
floitsch
2013/04/05 12:38:17
move to _SetMixin.
|
| +} |
| + |
| +// Implementation of Set methods shared by Set implementations. |
| +abstract class _SetMixin<E> { |
| + Set<E> _newSet(); |
| + |
| // Set. |
| bool isSubsetOf(Collection<E> other) { |
| // Deprecated, and using old signature. |
| @@ -94,25 +99,39 @@ class HashSet<E> extends Collection<E> implements Set<E> { |
| } else { |
| otherSet = other.toSet(); |
| } |
| - return IterableMixinWorkaround.setContainsAll(otherSet, this); |
| + return otherSet.containsAll(this); |
| } |
| bool containsAll(Iterable<E> other) { |
| - return IterableMixinWorkaround.setContainsAll(this, other); |
| + for (E object in other) { |
| + if (_table._get(object) < 0) return false; |
| + } |
| + return true; |
| } |
| Set<E> intersection(Set<E> other) { |
| - return IterableMixinWorkaround.setIntersection( |
| - this, other, new HashSet<E>()); |
| + Set<E> result = _newSet(); |
| + if (other.length < this.length) { |
| + for (E element in other) { |
| + if (this.contains(element)) result.add(element); |
| + } |
| + } else { |
| + for (E element in this) { |
| + if (other.contains(element)) result.add(element); |
| + } |
| + } |
| + return result; |
| } |
| Set<E> union(Set<E> other) { |
| - return IterableMixinWorkaround.setUnion(this, other, new HashSet<E>()); |
| + return _newSet()..addAll(this)..addAll(other); |
| } |
| Set<E> difference(Set<E> other) { |
| - return IterableMixinWorkaround.setDifference(this, other, new HashSet<E>()); |
| + HashSet<E> result = _newSet(); |
| + for (E element in this) { |
| + if (!other.contains(element)) result.add(element); |
| + } |
| + return result; |
| } |
| - |
| - String toString() => Collections.collectionToString(this); |
| } |