Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(659)

Unified Diff: sdk/lib/collection/hash_set.dart

Issue 13685004: Reduce usage of ItearbleMixinWorkaround. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix bug in set-base Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « samples/swarm/swarm_ui_lib/observable/observable.dart ('k') | sdk/lib/collection/linked_hash_set.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/collection/hash_set.dart
diff --git a/sdk/lib/collection/hash_set.dart b/sdk/lib/collection/hash_set.dart
index 977dcfff5bec0b6a5f12ae072933053af03be6c6..04516fc02d7a759ebd3fca97ca8092b70c02cde2 100644
--- a/sdk/lib/collection/hash_set.dart
+++ b/sdk/lib/collection/hash_set.dart
@@ -4,7 +4,57 @@
part of dart.collection;
-class HashSet<E> extends Collection<E> implements Set<E> {
+/** Common parts of [HashSet] and [LinkedHashSet] implementations. */
+abstract class _HashSetBase<E> extends Collection<E> implements Set<E> {
+ // Set.
+ bool isSubsetOf(Collection<E> other) {
+ // Deprecated, and using old signature.
+ Set otherSet;
+ if (other is Set) {
+ otherSet = other;
+ } else {
+ otherSet = other.toSet();
+ }
+ return otherSet.containsAll(this);
+ }
+
+ bool containsAll(Iterable<E> other) {
+ for (E object in other) {
+ if (!this.contains(object)) return false;
+ }
+ return true;
+ }
+
+ Set<E> intersection(Set<E> other) {
+ 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 _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;
+ }
+
+ String toString() => Collections.collectionToString(this);
+}
+
+class HashSet<E> extends _HashSetBase<E> {
external HashSet();
factory HashSet.from(Iterable<E> iterable) {
@@ -30,7 +80,13 @@ class HashSet<E> extends Collection<E> implements Set<E> {
external void removeAll(Iterable objectsToRemove);
void retainAll(Iterable objectsToRetain) {
- IterableMixinWorkaround.retainAll(this, objectsToRetain);
+ Set retainSet;
+ if (objectsToRetain is Set) {
+ retainSet = objectsToRetain;
+ } else {
+ retainSet = objectsToRetain.toSet();
+ }
+ retainWhere(retainSet.contains);
}
external void removeWhere(bool test(E element));
@@ -40,33 +96,5 @@ class HashSet<E> extends Collection<E> implements Set<E> {
external void clear();
// Set.
- bool isSubsetOf(Collection<E> other) {
- // Deprecated, and using old signature.
- Set otherSet;
- if (other is Set) {
- otherSet = other;
- } else {
- otherSet = other.toSet();
- }
- return IterableMixinWorkaround.setContainsAll(otherSet, this);
- }
-
- bool containsAll(Iterable<E> other) {
- return IterableMixinWorkaround.setContainsAll(this, other);
- }
-
- Set<E> intersection(Set<E> other) {
- return IterableMixinWorkaround.setIntersection(
- this, other, new HashSet<E>());
- }
-
- Set<E> union(Set<E> other) {
- return IterableMixinWorkaround.setUnion(this, other, new HashSet<E>());
- }
-
- Set<E> difference(Set<E> other) {
- return IterableMixinWorkaround.setDifference(this, other, new HashSet<E>());
- }
-
- String toString() => Collections.collectionToString(this);
+ Set<E> _newSet() => new HashSet<E>();
}
« no previous file with comments | « samples/swarm/swarm_ui_lib/observable/observable.dart ('k') | sdk/lib/collection/linked_hash_set.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698