| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 patch class HashMap<K, V> { | 5 patch class HashMap<K, V> { |
| 6 /* patch */ factory HashMap({ bool equals(K key1, K key2), | 6 /* patch */ factory HashMap({ bool equals(K key1, K key2), |
| 7 int hashCode(K key), | 7 int hashCode(K key), |
| 8 bool isValidKey(potentialKey) }) { | 8 bool isValidKey(potentialKey) }) { |
| 9 if (isValidKey == null) { | 9 if (isValidKey == null) { |
| 10 if (hashCode == null) { | 10 if (hashCode == null) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 } | 28 } |
| 29 return new _CustomHashMap<K, V>(equals, hashCode, isValidKey); | 29 return new _CustomHashMap<K, V>(equals, hashCode, isValidKey); |
| 30 } | 30 } |
| 31 } | 31 } |
| 32 | 32 |
| 33 const int _MODIFICATION_COUNT_MASK = 0x3fffffff; | 33 const int _MODIFICATION_COUNT_MASK = 0x3fffffff; |
| 34 | 34 |
| 35 class _HashMap<K, V> implements HashMap<K, V> { | 35 class _HashMap<K, V> implements HashMap<K, V> { |
| 36 static const int _INITIAL_CAPACITY = 8; | 36 static const int _INITIAL_CAPACITY = 8; |
| 37 | 37 |
| 38 Type get runtimeType => HashMap; | |
| 39 | 38 |
| 40 int _elementCount = 0; | 39 int _elementCount = 0; |
| 41 List<_HashMapEntry> _buckets = new List(_INITIAL_CAPACITY); | 40 List<_HashMapEntry> _buckets = new List(_INITIAL_CAPACITY); |
| 42 int _modificationCount = 0; | 41 int _modificationCount = 0; |
| 43 | 42 |
| 44 int get length => _elementCount; | 43 int get length => _elementCount; |
| 45 bool get isEmpty => _elementCount == 0; | 44 bool get isEmpty => _elementCount == 0; |
| 46 bool get isNotEmpty => _elementCount != 0; | 45 bool get isNotEmpty => _elementCount != 0; |
| 47 | 46 |
| 48 Iterable<K> get keys => new _HashMapKeyIterable<K>(this); | 47 Iterable<K> get keys => new _HashMapKeyIterable<K>(this); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 String toString() => Maps.mapToString(this); | 218 String toString() => Maps.mapToString(this); |
| 220 } | 219 } |
| 221 | 220 |
| 222 class _CustomHashMap<K, V> extends _HashMap<K, V> { | 221 class _CustomHashMap<K, V> extends _HashMap<K, V> { |
| 223 final _Equality<K> _equals; | 222 final _Equality<K> _equals; |
| 224 final _Hasher<K> _hashCode; | 223 final _Hasher<K> _hashCode; |
| 225 final _Predicate _validKey; | 224 final _Predicate _validKey; |
| 226 _CustomHashMap(this._equals, this._hashCode, validKey) | 225 _CustomHashMap(this._equals, this._hashCode, validKey) |
| 227 : _validKey = (validKey != null) ? validKey : new _TypeTest<K>().test; | 226 : _validKey = (validKey != null) ? validKey : new _TypeTest<K>().test; |
| 228 | 227 |
| 229 Type get runtimeType => HashMap; | |
| 230 | 228 |
| 231 bool containsKey(Object key) { | 229 bool containsKey(Object key) { |
| 232 if (!_validKey(key)) return false; | 230 if (!_validKey(key)) return false; |
| 233 int hashCode = _hashCode(key); | 231 int hashCode = _hashCode(key); |
| 234 List buckets = _buckets; | 232 List buckets = _buckets; |
| 235 int index = hashCode & (buckets.length - 1); | 233 int index = hashCode & (buckets.length - 1); |
| 236 _HashMapEntry entry = buckets[index]; | 234 _HashMapEntry entry = buckets[index]; |
| 237 while (entry != null) { | 235 while (entry != null) { |
| 238 if (hashCode == entry.hashCode && _equals(entry.key, key)) return true; | 236 if (hashCode == entry.hashCode && _equals(entry.key, key)) return true; |
| 239 entry = entry.next; | 237 entry = entry.next; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 previous = entry; | 311 previous = entry; |
| 314 entry = next; | 312 entry = next; |
| 315 } | 313 } |
| 316 return null; | 314 return null; |
| 317 } | 315 } |
| 318 | 316 |
| 319 String toString() => Maps.mapToString(this); | 317 String toString() => Maps.mapToString(this); |
| 320 } | 318 } |
| 321 | 319 |
| 322 class _IdentityHashMap<K, V> extends _HashMap<K, V> { | 320 class _IdentityHashMap<K, V> extends _HashMap<K, V> { |
| 323 Type get runtimeType => HashMap; | |
| 324 | 321 |
| 325 bool containsKey(Object key) { | 322 bool containsKey(Object key) { |
| 326 int hashCode = key.hashCode; | 323 int hashCode = key.hashCode; |
| 327 List buckets = _buckets; | 324 List buckets = _buckets; |
| 328 int index = hashCode & (buckets.length - 1); | 325 int index = hashCode & (buckets.length - 1); |
| 329 _HashMapEntry entry = buckets[index]; | 326 _HashMapEntry entry = buckets[index]; |
| 330 while (entry != null) { | 327 while (entry != null) { |
| 331 if (hashCode == entry.hashCode && identical(entry.key, key)) return true; | 328 if (hashCode == entry.hashCode && identical(entry.key, key)) return true; |
| 332 entry = entry.next; | 329 entry = entry.next; |
| 333 } | 330 } |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 } | 894 } |
| 898 return new _LinkedCustomHashMap<K, V>(equals, hashCode, isValidKey); | 895 return new _LinkedCustomHashMap<K, V>(equals, hashCode, isValidKey); |
| 899 } | 896 } |
| 900 } | 897 } |
| 901 | 898 |
| 902 // Methods that are exactly the same in all three linked hash map variants. | 899 // Methods that are exactly the same in all three linked hash map variants. |
| 903 abstract class _LinkedHashMapMixin<K, V> implements LinkedHashMap<K, V> { | 900 abstract class _LinkedHashMapMixin<K, V> implements LinkedHashMap<K, V> { |
| 904 var _nextEntry; | 901 var _nextEntry; |
| 905 var _previousEntry; | 902 var _previousEntry; |
| 906 | 903 |
| 907 Type get runtimeType => LinkedHashMap; | |
| 908 | 904 |
| 909 bool containsValue(Object value) { | 905 bool containsValue(Object value) { |
| 910 int modificationCount = _modificationCount; | 906 int modificationCount = _modificationCount; |
| 911 var cursor = _nextEntry; | 907 var cursor = _nextEntry; |
| 912 while (!identical(cursor, this)) { | 908 while (!identical(cursor, this)) { |
| 913 _HashMapEntry entry = cursor; | 909 _HashMapEntry entry = cursor; |
| 914 if (entry.value == value) return true; | 910 if (entry.value == value) return true; |
| 915 if (modificationCount != _modificationCount) { | 911 if (modificationCount != _modificationCount) { |
| 916 throw new ConcurrentModificationError(this); | 912 throw new ConcurrentModificationError(this); |
| 917 } | 913 } |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1202 return false; | 1198 return false; |
| 1203 } | 1199 } |
| 1204 _LinkedHashSetEntry entry = _next; | 1200 _LinkedHashSetEntry entry = _next; |
| 1205 _current = entry.key; | 1201 _current = entry.key; |
| 1206 _next = entry._nextEntry; | 1202 _next = entry._nextEntry; |
| 1207 return true; | 1203 return true; |
| 1208 } | 1204 } |
| 1209 | 1205 |
| 1210 E get current => _current; | 1206 E get current => _current; |
| 1211 } | 1207 } |
| OLD | NEW |