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 59c63b958a0530b3a1cef731afd2333197e91145..e866b6369893b8a1e999f91104cb931864bf1a4c 100644 |
--- a/sdk/lib/collection/linked_hash_set.dart |
+++ b/sdk/lib/collection/linked_hash_set.dart |
@@ -5,124 +5,49 @@ |
part of dart.collection; |
class LinkedHashSet<E> extends _HashSetBase<E> { |
- static const int _INITIAL_CAPACITY = 8; |
- _LinkedHashTable<E> _table; |
- LinkedHashSet() : _table = new _LinkedHashTable(_INITIAL_CAPACITY) { |
- _table._container = this; |
- } |
+ external LinkedHashSet(); |
factory LinkedHashSet.from(Iterable<E> iterable) { |
return new LinkedHashSet<E>()..addAll(iterable); |
} |
// Iterable. |
- Iterator<E> get iterator => new _LinkedHashTableKeyIterator<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); |
- void forEach(void action(E element)) { |
- int offset = _table._next(_LinkedHashTable._HEAD_OFFSET); |
- int modificationCount = _table._modificationCount; |
- while (offset != _LinkedHashTable._HEAD_OFFSET) { |
- E key = _table._key(offset); |
- action(key); |
- _table._checkModification(modificationCount); |
- offset = _table._next(offset); |
- } |
- } |
+ external void forEach(void action(E element)); |
- E get first { |
- int firstOffset = _table._next(_LinkedHashTable._HEAD_OFFSET); |
- if (firstOffset == _LinkedHashTable._HEAD_OFFSET) { |
- throw new StateError("No elements"); |
- } |
- return _table._key(firstOffset); |
- } |
+ external E get first; |
- E get last { |
- int lastOffset = _table._prev(_LinkedHashTable._HEAD_OFFSET); |
- if (lastOffset == _LinkedHashTable._HEAD_OFFSET) { |
- throw new StateError("No elements"); |
- } |
- return _table._key(lastOffset); |
- } |
+ external E get last; |
E get single { |
- int firstOffset = _table._next(_LinkedHashTable._HEAD_OFFSET); |
- if (firstOffset == _LinkedHashTable._HEAD_OFFSET) { |
- throw new StateError("No elements"); |
- } |
- int lastOffset = _table._prev(_LinkedHashTable._HEAD_OFFSET); |
- if (lastOffset != firstOffset) { |
- throw new StateError("Too many elements"); |
- } |
- return _table._key(firstOffset); |
+ if (length == 1) return first; |
+ var message = (length == 0) ? "No Elements" : "Too many elements"; |
+ throw new StateError(message); |
} |
// Collection. |
- void _filterWhere(bool test(E element), bool removeMatching) { |
- int entrySize = _table._entrySize; |
- int length = _table._table.length; |
- int offset = _table._next(_LinkedHashTable._HEAD_OFFSET); |
- while (offset != _LinkedHashTable._HEAD_OFFSET) { |
- E key = _table._key(offset); |
- int nextOffset = _table._next(offset); |
- int modificationCount = _table._modificationCount; |
- bool shouldRemove = (removeMatching == test(key)); |
- _table._checkModification(modificationCount); |
- if (shouldRemove) { |
- _table._deleteEntry(offset); |
- } |
- offset = nextOffset; |
- } |
- _table._checkCapacity(); |
- } |
+ external void add(E element); |
- void add(E element) { |
- _table._put(element); |
- _table._checkCapacity(); |
- } |
+ external void addAll(Iterable<E> objects); |
- bool remove(Object object) { |
- int offset = _table._remove(object); |
- if (offset >= 0) { |
- _table._checkCapacity(); |
- return true; |
- } |
- return false; |
- } |
+ external bool remove(Object object); |
- void removeAll(Iterable objectsToRemove) { |
- for (Object object in objectsToRemove) { |
- if (_table._remove(object) >= 0) { |
- _table._checkCapacity(); |
- } |
- } |
- } |
+ external void removeAll(Iterable objectsToRemove); |
- void retainAll(Iterable objectsToRetain) { |
- Set retainSet; |
- if (objectsToRetain is Set) { |
- retainSet = objectsToRetain; |
- } else { |
- retainSet = objectsToRetain.toSet(); |
- } |
- _filterWhere(retainSet.contains, false); |
- } |
+ external void removeWhere(bool test(E element)); |
- void removeWhere(bool test(E element)) { |
- _filterWhere(test, true); |
- } |
+ external void retainWhere(bool test(E element)); |
- retianWhere(bool test(E element)) { |
- _filterWhere(test, false); |
- } |
+ external void clear(); |
- // Set |
+ // Set. |
Set<E> _newSet() => new LinkedHashSet<E>(); |
} |