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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 * | 56 * |
57 * It is generally the case that if you supply one of [equals] and [hashCode], | 57 * It is generally the case that if you supply one of [equals] and [hashCode], |
58 * you also want to supply the other. The only common exception is to pass | 58 * you also want to supply the other. The only common exception is to pass |
59 * [identical] as the equality and use the default hash code. | 59 * [identical] as the equality and use the default hash code. |
60 */ | 60 */ |
61 external factory HashMap({bool equals(K key1, K key2), | 61 external factory HashMap({bool equals(K key1, K key2), |
62 int hashCode(K key), | 62 int hashCode(K key), |
63 bool isValidKey(potentialKey)}); | 63 bool isValidKey(potentialKey)}); |
64 | 64 |
65 /** | 65 /** |
| 66 * Creates an unordered identity-based map. |
| 67 * |
| 68 * Effectively a shorthand for: |
| 69 * |
| 70 * new HashMap(equals: identical, hashCode: identityHashCodeOf) |
| 71 */ |
| 72 external factory HashMap.identity(); |
| 73 |
| 74 /** |
66 * Creates a [HashMap] that contains all key value pairs of [other]. | 75 * Creates a [HashMap] that contains all key value pairs of [other]. |
67 */ | 76 */ |
68 factory HashMap.from(Map<K, V> other) { | 77 factory HashMap.from(Map<K, V> other) { |
69 return new HashMap<K, V>()..addAll(other); | 78 return new HashMap<K, V>()..addAll(other); |
70 } | 79 } |
71 | 80 |
72 /** | 81 /** |
73 * Creates a [HashMap] where the keys and values are computed from the | 82 * Creates a [HashMap] where the keys and values are computed from the |
74 * [iterable]. | 83 * [iterable]. |
75 * | 84 * |
(...skipping 23 matching lines...) Expand all Loading... |
99 * overwrites the previous value. | 108 * overwrites the previous value. |
100 * | 109 * |
101 * It is an error if the two [Iterable]s don't have the same length. | 110 * It is an error if the two [Iterable]s don't have the same length. |
102 */ | 111 */ |
103 factory HashMap.fromIterables(Iterable<K> keys, Iterable<V> values) { | 112 factory HashMap.fromIterables(Iterable<K> keys, Iterable<V> values) { |
104 HashMap<K, V> map = new HashMap<K, V>(); | 113 HashMap<K, V> map = new HashMap<K, V>(); |
105 Maps._fillMapWithIterables(map, keys, values); | 114 Maps._fillMapWithIterables(map, keys, values); |
106 return map; | 115 return map; |
107 } | 116 } |
108 } | 117 } |
OLD | NEW |