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

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

Issue 13715002: Add a dart2js specific HashSet implementation that follows the HashMap implementation fairly closel… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address feedback. 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/_internal/compiler/implementation/lib/collection_patch.dart ('k') | no next file » | 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..977dcfff5bec0b6a5f12ae072933053af03be6c6 100644
--- a/sdk/lib/collection/hash_set.dart
+++ b/sdk/lib/collection/hash_set.dart
@@ -5,85 +5,39 @@
part of dart.collection;
class HashSet<E> extends Collection<E> implements Set<E> {
- static const int _INITIAL_CAPACITY = 8;
- final _HashTable<E> _table;
-
- HashSet() : _table = new _HashTable(_INITIAL_CAPACITY) {
- _table._container = this;
- }
+ external HashSet();
factory HashSet.from(Iterable<E> iterable) {
return new HashSet<E>()..addAll(iterable);
}
// Iterable.
- Iterator<E> get iterator => new _HashTableKeyIterator<E>(_table);
+ external Iterator<E> get iterator;
- int get length => _table._elementCount;
+ external int get length;
- bool get isEmpty => _table._elementCount == 0;
+ external bool get isEmpty;
- bool contains(Object object) => _table._get(object) >= 0;
+ external bool contains(Object object);
// Collection.
- void add(E element) {
- _table._put(element);
- _table._checkCapacity();
- }
+ external void add(E element);
- void addAll(Iterable<E> objects) {
- for (E object in objects) {
- _table._put(object);
- _table._checkCapacity();
- }
- }
+ external void addAll(Iterable<E> objects);
- bool remove(Object object) {
- int offset = _table._remove(object);
- _table._checkCapacity();
- return offset >= 0;
- }
+ external bool remove(Object object);
- void removeAll(Iterable objectsToRemove) {
- for (Object object in objectsToRemove) {
- _table._remove(object);
- _table._checkCapacity();
- }
- }
+ external void removeAll(Iterable objectsToRemove);
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;
- for (int offset = 0; offset < length; offset += entrySize) {
- Object entry = _table._table[offset];
- if (!_table._isFree(entry)) {
- E key = identical(entry, _NULL) ? null : entry;
- int modificationCount = _table._modificationCount;
- bool shouldRemove = (removeMatching == test(key));
- _table._checkModification(modificationCount);
- if (shouldRemove) {
- _table._deleteEntry(offset);
- }
- }
- }
- _table._checkCapacity();
- }
+ external void removeWhere(bool test(E element));
- void removeWhere(bool test(E element)) {
- _filterWhere(test, true);
- }
+ external void retainWhere(bool test(E element));
- void retainWhere(bool test(E element)) {
- _filterWhere(test, false);
- }
-
- void clear() {
- _table._clear();
- }
+ external void clear();
// Set.
bool isSubsetOf(Collection<E> other) {
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/lib/collection_patch.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698