OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 // Hash map implementation with open addressing and quadratic probing. | 5 // Hash map implementation with open addressing and quadratic probing. |
6 class HashMapImplementation<K extends Hashable, V> implements HashMap<K, V> { | 6 class HashMapImplementation<K, V> implements HashMap<K, V> { |
7 | 7 |
8 // The [_keys] list contains the keys inserted in the map. | 8 // The [_keys] list contains the keys inserted in the map. |
9 // The [_keys] list must be a raw list because it | 9 // The [_keys] list must be a raw list because it |
10 // will contain both elements of type K, and the [_DELETED_KEY] of type | 10 // will contain both elements of type K, and the [_DELETED_KEY] of type |
11 // [_DeletedKeySentinel]. | 11 // [_DeletedKeySentinel]. |
12 // The alternative of declaring the [_keys] list as of type Object | 12 // The alternative of declaring the [_keys] list as of type Object |
13 // does not work, because the HashSetIterator constructor would fail: | 13 // does not work, because the HashSetIterator constructor would fail: |
14 // HashSetIterator(HashSet<E> set) | 14 // HashSetIterator(HashSet<E> set) |
15 // : _nextValidIndex = -1, | 15 // : _nextValidIndex = -1, |
16 // _entries = set_._backingMap._keys { | 16 // _entries = set_._backingMap._keys { |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 } | 269 } |
270 } | 270 } |
271 return false; | 271 return false; |
272 } | 272 } |
273 | 273 |
274 String toString() { | 274 String toString() { |
275 return Maps.mapToString(this); | 275 return Maps.mapToString(this); |
276 } | 276 } |
277 } | 277 } |
278 | 278 |
279 class HashSetImplementation<E extends Hashable> implements HashSet<E> { | 279 class HashSetImplementation<E > implements HashSet<E> { |
Mads Ager (google)
2012/09/27 12:48:27
Extra space.
| |
280 | 280 |
281 HashSetImplementation() { | 281 HashSetImplementation() { |
282 _backingMap = new HashMapImplementation<E, E>(); | 282 _backingMap = new HashMapImplementation<E, E>(); |
283 } | 283 } |
284 | 284 |
285 factory HashSetImplementation.from(Iterable<E> other) { | 285 factory HashSetImplementation.from(Iterable<E> other) { |
286 Set<E> set = new HashSetImplementation<E>(); | 286 Set<E> set = new HashSetImplementation<E>(); |
287 for (final e in other) { | 287 for (final e in other) { |
288 set.add(e); | 288 set.add(e); |
289 } | 289 } |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
447 | 447 |
448 /** | 448 /** |
449 * A singleton sentinel used to represent when a key is deleted from the map. | 449 * A singleton sentinel used to represent when a key is deleted from the map. |
450 * We can't use [: const Object() :] as a sentinel because it would end up | 450 * We can't use [: const Object() :] as a sentinel because it would end up |
451 * canonicalized and then we cannot distinguish the deleted key from the | 451 * canonicalized and then we cannot distinguish the deleted key from the |
452 * canonicalized [: Object() :]. | 452 * canonicalized [: Object() :]. |
453 */ | 453 */ |
454 class _DeletedKeySentinel { | 454 class _DeletedKeySentinel { |
455 const _DeletedKeySentinel(); | 455 const _DeletedKeySentinel(); |
456 } | 456 } |
OLD | NEW |