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

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

Issue 13598015: Revert 20969: Reduce usage of IterableMixinWorkaround (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 | « sdk/lib/collection/hash_set.dart ('k') | sdk/lib/collection/queue.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 48d48c8d2ca3d711e6dc6848be93a0991770948e..8a4d566130ce6b821fdda7af8dc53518ac83a215 100644
--- a/sdk/lib/collection/linked_hash_set.dart
+++ b/sdk/lib/collection/linked_hash_set.dart
@@ -4,7 +4,7 @@
part of dart.collection;
-class LinkedHashSet<E> extends _HashSetBase<E> {
+class LinkedHashSet<E> extends Collection<E> implements Set<E> {
static const int _INITIAL_CAPACITY = 8;
_LinkedHashTable<E> _table;
@@ -19,12 +19,6 @@ class LinkedHashSet<E> extends _HashSetBase<E> {
// Iterable.
Iterator<E> get iterator => new _LinkedHashTableKeyIterator<E>(_table);
- int get length => _table._elementCount;
-
- bool get isEmpty => _table._elementCount == 0;
-
- bool contains(Object object) => _table._get(object) >= 0;
-
void forEach(void action(E element)) {
int offset = _table._next(_LinkedHashTable._HEAD_OFFSET);
int modificationCount = _table._modificationCount;
@@ -36,6 +30,12 @@ class LinkedHashSet<E> extends _HashSetBase<E> {
}
}
+ int get length => _table._elementCount;
+
+ bool get isEmpty => _table._elementCount == 0;
+
+ bool contains(Object object) => _table._get(object) >= 0;
+
E get first {
int firstOffset = _table._next(_LinkedHashTable._HEAD_OFFSET);
if (firstOffset == _LinkedHashTable._HEAD_OFFSET) {
@@ -65,6 +65,38 @@ class LinkedHashSet<E> extends _HashSetBase<E> {
}
// Collection.
+ void add(E element) {
+ _table._put(element);
+ _table._checkCapacity();
+ }
+
+ void addAll(Iterable<E> objects) {
+ for (E object in objects) {
+ _table._put(object);
+ _table._checkCapacity();
+ }
+ }
+
+ bool remove(Object object) {
+ int offset = _table._remove(object);
+ if (offset >= 0) {
+ _table._checkCapacity();
+ return true;
+ }
+ return false;
+ }
+
+ void removeAll(Iterable objectsToRemove) {
+ for (Object object in objectsToRemove) {
+ _table._remove(object);
+ _table._checkCapacity();
+ }
+ }
+
+ void retainAll(Iterable objectsToRemove) {
+ IterableMixinWorkaround.retainAll(this, objectsToRemove);
+ }
+
void _filterWhere(bool test(E element), bool removeMatching) {
int entrySize = _table._entrySize;
int length = _table._table.length;
@@ -83,46 +115,48 @@ class LinkedHashSet<E> extends _HashSetBase<E> {
_table._checkCapacity();
}
- void add(E element) {
- _table._put(element);
- _table._checkCapacity();
+ void removeWhere(bool test(E element)) {
+ _filterWhere(test, true);
}
- bool remove(Object object) {
- int offset = _table._remove(object);
- if (offset >= 0) {
- _table._checkCapacity();
- return true;
- }
- return false;
+ void retainWhere(bool test(E element)) {
+ _filterWhere(test, false);
}
- void removeAll(Iterable objectsToRemove) {
- for (Object object in objectsToRemove) {
- if (_table.remove(object) >= 0) {
- _table._checkCapacity();
- }
- }
+ void clear() {
+ _table._clear();
}
- void retainAll(Iterable objectsToRetain) {
- Set retainSet;
- if (objectsToRetain is Set) {
- retainSet = objectsToRetain;
+ // Set.
+ bool isSubsetOf(Collection<E> other) {
+ // Deprecated, and using old signature.
+ Set otherSet;
+ if (other is Set) {
+ otherSet = other;
} else {
- retainSet = objectsToRetain.toSet();
+ otherSet = other.toSet();
}
- _filterWhere(retainSet.contains, false);
+ return IterableMixinWorkaround.setContainsAll(otherSet, this);
}
- void removeWhere(bool test(E element)) {
- _filterWhere(test, true);
+ bool containsAll(Iterable<E> other) {
+ return IterableMixinWorkaround.setContainsAll(this, other);
}
- retianWhere(bool test(E element)) {
- _filterWhere(test, false);
+ Set<E> intersection(Set<E> other) {
+ return IterableMixinWorkaround.setIntersection(
+ this, other, new LinkedHashSet<E>());
+ }
+
+ Set<E> union(Set<E> other) {
+ return IterableMixinWorkaround.setUnion(
+ this, other, new LinkedHashSet<E>());
+ }
+
+ Set<E> difference(Set<E> other) {
+ return IterableMixinWorkaround.setDifference(
+ this, other, new LinkedHashSet<E>());
}
- // Set
- Set<E> _newSet() => new LinkedHashSet<E>();
+ String toString() => Collections.collectionToString(this);
}
« no previous file with comments | « sdk/lib/collection/hash_set.dart ('k') | sdk/lib/collection/queue.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698