| Index: sdk/lib/collection/hash_map.dart
|
| diff --git a/sdk/lib/collection/hash_map.dart b/sdk/lib/collection/hash_map.dart
|
| index d90b4b9f0646c5ebbb689695696bf87f07a94d51..0fe35262cd4d5bab4ecad189e55747cab5321f61 100644
|
| --- a/sdk/lib/collection/hash_map.dart
|
| +++ b/sdk/lib/collection/hash_map.dart
|
| @@ -21,116 +21,32 @@ class _HashMapTable<K, V> extends _HashTable<K> {
|
| }
|
|
|
| class HashMap<K, V> implements Map<K, V> {
|
| - final _HashMapTable<K, V> _hashTable;
|
| -
|
| - HashMap() : _hashTable = new _HashMapTable<K, V>() {
|
| - _hashTable._container = this;
|
| - }
|
| + external HashMap();
|
|
|
| factory HashMap.from(Map<K, V> other) {
|
| return new HashMap<K, V>()..addAll(other);
|
| }
|
|
|
| - bool containsKey(K key) {
|
| - return _hashTable._get(key) >= 0;
|
| - }
|
| -
|
| - bool containsValue(V value) {
|
| - List table = _hashTable._table;
|
| - int entrySize = _hashTable._entrySize;
|
| - for (int offset = 0; offset < table.length; offset += entrySize) {
|
| - if (!_hashTable._isFree(table[offset]) &&
|
| - _hashTable._value(offset) == value) {
|
| - return true;
|
| - }
|
| - }
|
| - return false;
|
| - }
|
| + external int get length;
|
| + external bool get isEmpty;
|
|
|
| - void addAll(Map<K, V> other) {
|
| - other.forEach((K key, V value) {
|
| - int offset = _hashTable._put(key);
|
| - _hashTable._setValue(offset, value);
|
| - _hashTable._checkCapacity();
|
| - });
|
| - }
|
| + external Iterable<K> get keys;
|
| + external Iterable<V> get values;
|
|
|
| - V operator [](K key) {
|
| - int offset = _hashTable._get(key);
|
| - if (offset >= 0) return _hashTable._value(offset);
|
| - return null;
|
| - }
|
| + external bool containsKey(K key);
|
| + external bool containsValue(V value);
|
|
|
| - void operator []=(K key, V value) {
|
| - int offset = _hashTable._put(key);
|
| - _hashTable._setValue(offset, value);
|
| - _hashTable._checkCapacity();
|
| - }
|
| + external void addAll(Map<K, V> other);
|
|
|
| - V putIfAbsent(K key, V ifAbsent()) {
|
| - int offset = _hashTable._probeForAdd(_hashTable._hashCodeOf(key), key);
|
| - Object entry = _hashTable._table[offset];
|
| - if (!_hashTable._isFree(entry)) {
|
| - return _hashTable._value(offset);
|
| - }
|
| - int modificationCount = _hashTable._modificationCount;
|
| - V value = ifAbsent();
|
| - if (modificationCount == _hashTable._modificationCount) {
|
| - _hashTable._setKey(offset, key);
|
| - _hashTable._setValue(offset, value);
|
| - if (entry == null) {
|
| - _hashTable._entryCount++;
|
| - _hashTable._checkCapacity();
|
| - } else {
|
| - assert(identical(entry, _TOMBSTONE));
|
| - _hashTable._deletedCount--;
|
| - }
|
| - _hashTable._recordModification();
|
| - } else {
|
| - // The table might have changed, so we can't trust [offset] any more.
|
| - // Do another lookup before setting the value.
|
| - offset = _hashTable._put(key);
|
| - _hashTable._setValue(offset, value);
|
| - _hashTable._checkCapacity();
|
| - }
|
| - return value;
|
| - }
|
| -
|
| - V remove(K key) {
|
| - int offset = _hashTable._remove(key);
|
| - if (offset < 0) return null;
|
| - V oldValue = _hashTable._value(offset);
|
| - _hashTable._setValue(offset, null);
|
| - _hashTable._checkCapacity();
|
| - return oldValue;
|
| - }
|
| -
|
| - void clear() {
|
| - _hashTable._clear();
|
| - }
|
| -
|
| - void forEach(void action (K key, V value)) {
|
| - int modificationCount = _hashTable._modificationCount;
|
| - List table = _hashTable._table;
|
| - int entrySize = _hashTable._entrySize;
|
| - for (int offset = 0; offset < table.length; offset += entrySize) {
|
| - Object entry = table[offset];
|
| - if (!_hashTable._isFree(entry)) {
|
| - K key = entry;
|
| - V value = _hashTable._value(offset);
|
| - action(key, value);
|
| - _hashTable._checkModification(modificationCount);
|
| - }
|
| - }
|
| - }
|
| + external V operator [](K key);
|
| + external void operator []=(K key, V value);
|
|
|
| - Iterable<K> get keys => new _HashTableKeyIterable<K>(_hashTable);
|
| - Iterable<V> get values =>
|
| - new _HashTableValueIterable<V>(_hashTable, _HashMapTable._VALUE_INDEX);
|
| + external V putIfAbsent(K key, V ifAbsent());
|
|
|
| - int get length => _hashTable._elementCount;
|
| + external V remove(K key);
|
| + external void clear();
|
|
|
| - bool get isEmpty => _hashTable._elementCount == 0;
|
| + external void forEach(void action(K key, V value));
|
|
|
| String toString() => Maps.mapToString(this);
|
| }
|
|
|