Chromium Code Reviews| 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 part of dart.collection; | 5 part of dart.collection; |
| 6 | 6 |
| 7 /** Default function for equality comparison in customized HashMaps */ | 7 /** Default function for equality comparison in customized HashMaps */ |
| 8 bool _defaultEquals(a, b) => a == b; | 8 bool _defaultEquals(a, b) => a == b; |
| 9 /** Default function for hash-code computation in customized HashMaps */ | 9 /** Default function for hash-code computation in customized HashMaps */ |
| 10 int _defaultHashCode(a) => a.hashCode; | 10 int _defaultHashCode(a) => a.hashCode; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 /** | 73 /** |
| 74 * Creates an unordered identity-based map. | 74 * Creates an unordered identity-based map. |
| 75 * | 75 * |
| 76 * Effectively a shorthand for: | 76 * Effectively a shorthand for: |
| 77 * | 77 * |
| 78 * new HashMap(equals: identical, hashCode: identityHashCodeOf) | 78 * new HashMap(equals: identical, hashCode: identityHashCodeOf) |
| 79 */ | 79 */ |
| 80 external factory HashMap.identity(); | 80 external factory HashMap.identity(); |
| 81 | 81 |
| 82 /** | 82 /** |
| 83 * Creates a [HashMap] that contains all key value pairs of [other]. | 83 * Creates a [HashMap] that contains all key/value pairs of [other]. |
| 84 */ | 84 */ |
| 85 factory HashMap.from(Map<K, V> other) { | 85 factory HashMap.from(Map other) { |
| 86 return new HashMap<K, V>()..addAll(other); | 86 HashMap<K, V> result = new HashMap<K, V>(); |
| 87 other.forEach((k, v) { result[k] = v; }); | |
|
Søren Gjesse
2015/01/05 15:35:15
Add types K and V?
Lasse Reichstein Nielsen
2015/01/06 10:14:45
The forEach method has type (K',V')->void where ot
Søren Gjesse
2015/01/06 12:09:05
Of cause.
| |
| 88 return result; | |
| 87 } | 89 } |
| 88 | 90 |
| 89 /** | 91 /** |
| 90 * Creates a [HashMap] where the keys and values are computed from the | 92 * Creates a [HashMap] where the keys and values are computed from the |
| 91 * [iterable]. | 93 * [iterable]. |
| 92 * | 94 * |
| 93 * For each element of the [iterable] this constructor computes a key/value | 95 * For each element of the [iterable] this constructor computes a key/value |
| 94 * pair, by applying [key] and [value] respectively. | 96 * pair, by applying [key] and [value] respectively. |
| 95 * | 97 * |
| 96 * The keys of the key/value pairs do not need to be unique. The last | 98 * The keys of the key/value pairs do not need to be unique. The last |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 116 * overwrites the previous value. | 118 * overwrites the previous value. |
| 117 * | 119 * |
| 118 * It is an error if the two [Iterable]s don't have the same length. | 120 * It is an error if the two [Iterable]s don't have the same length. |
| 119 */ | 121 */ |
| 120 factory HashMap.fromIterables(Iterable<K> keys, Iterable<V> values) { | 122 factory HashMap.fromIterables(Iterable<K> keys, Iterable<V> values) { |
| 121 HashMap<K, V> map = new HashMap<K, V>(); | 123 HashMap<K, V> map = new HashMap<K, V>(); |
| 122 Maps._fillMapWithIterables(map, keys, values); | 124 Maps._fillMapWithIterables(map, keys, values); |
| 123 return map; | 125 return map; |
| 124 } | 126 } |
| 125 } | 127 } |
| OLD | NEW |