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

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: 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 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);
}
« 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