Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Unified Diff: tool/input_sdk/lib/collection/hash_map.dart

Issue 1956933002: Update collection (list / map / iterable) printing. (Closed) Base URL: https://github.com/dart-lang/dev_compiler@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tool/input_sdk/lib/collection/collections.dart ('k') | tool/input_sdk/lib/collection/hash_set.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tool/input_sdk/lib/collection/hash_map.dart
diff --git a/tool/input_sdk/lib/collection/hash_map.dart b/tool/input_sdk/lib/collection/hash_map.dart
index 003cd4f18c8b642fe3df060d72093d26a57fb77c..dacf929e0ac2e9687b3e8e60f0961e6b7e24faad 100644
--- a/tool/input_sdk/lib/collection/hash_map.dart
+++ b/tool/input_sdk/lib/collection/hash_map.dart
@@ -5,9 +5,9 @@
part of dart.collection;
/** Default function for equality comparison in customized HashMaps */
-bool _defaultEquals(Object a, Object b) => a == b;
+bool _defaultEquals(a, b) => a == b;
/** Default function for hash-code computation in customized HashMaps */
-int _defaultHashCode(Object a) => a.hashCode;
+int _defaultHashCode(a) => a.hashCode;
/** Type of custom equality function */
typedef bool _Equality<K>(K a, K b);
@@ -27,7 +27,7 @@ typedef int _Hasher<K>(K object);
*
* Iterating the map's keys, values or entries (through [forEach])
* may happen in any order.
- * The itearation order only changes when the map is modified.
+ * The iteration order only changes when the map is modified.
* Values are iterated in the same order as their associated keys,
* so iterating the [keys] and [values] in parallel
* will give matching key and value pairs.
@@ -56,15 +56,32 @@ abstract class HashMap<K, V> implements Map<K, V> {
* The [isValidKey] function defaults to just testing if the object is a
* [K] instance.
*
+ * Example:
+ *
+ * new HashMap<int,int>(equals: (int a, int b) => (b - a) % 5 == 0,
+ * hashCode: (int e) => e % 5)
+ *
+ * This example map does not need an `isValidKey` function to be passed.
+ * The default function accepts only `int` values, which can safely be
+ * passed to both the `equals` and `hashCode` functions.
+ *
+ * If neither `equals`, `hashCode`, nor `isValidKey` is provided,
+ * the default `isValidKey` instead accepts all keys.
+ * The default equality and hashcode operations are assumed to work on all
+ * objects.
+ *
+ * Likewise, if `equals` is [identical], `hashCode` is [identityHashCode]
+ * and `isValidKey` is omitted, the resulting map is identity based,
+ * and the `isValidKey` defaults to accepting all keys.
+ * Such a map can be created directly using [HashMap.identity].
+ *
* The used `equals` and `hashCode` method should always be consistent,
* so that if `equals(a, b)` then `hashCode(a) == hashCode(b)`. The hash
* of an object, or what it compares equal to, should not change while the
- * object is in the table. If it does change, the result is unpredictable.
+ * object is a key in the map. If it does change, the result is unpredictable.
*
* If you supply one of [equals] and [hashCode],
* you should generally also to supply the other.
- * An example would be using [identical] and [identityHashCode],
- * which is equivalent to using the shorthand [HashMap.identity]).
*/
external factory HashMap({bool equals(K key1, K key2),
int hashCode(K key),
@@ -75,7 +92,8 @@ abstract class HashMap<K, V> implements Map<K, V> {
*
* Effectively a shorthand for:
*
- * new HashMap(equals: identical, hashCode: identityHashCodeOf)
+ * new HashMap(equals: identical,
+ * hashCode: identityHashCode)
*/
external factory HashMap.identity();
@@ -84,7 +102,7 @@ abstract class HashMap<K, V> implements Map<K, V> {
*/
factory HashMap.from(Map other) {
HashMap<K, V> result = new HashMap<K, V>();
- other.forEach((k, v) { result[k] = v; });
+ other.forEach((k, v) { result[k as K] = v as V; });
return result;
}
« no previous file with comments | « tool/input_sdk/lib/collection/collections.dart ('k') | tool/input_sdk/lib/collection/hash_set.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698