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

Unified Diff: sdk/lib/collection/linked_hash_map.dart

Issue 1130453003: Update {,Linked}Hash{Set,Map} documentation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 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 | « sdk/lib/collection/hash_set.dart ('k') | sdk/lib/collection/linked_hash_set.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/collection/linked_hash_map.dart
diff --git a/sdk/lib/collection/linked_hash_map.dart b/sdk/lib/collection/linked_hash_map.dart
index e1bca0f509645ba2441fb12b13028ee64768bc1c..e06f9e6644ea24573404a6f588965713579689d4 100644
--- a/sdk/lib/collection/linked_hash_map.dart
+++ b/sdk/lib/collection/linked_hash_map.dart
@@ -43,6 +43,25 @@ abstract class LinkedHashMap<K, V> implements HashMap<K, V> {
* The [isValidKey] function defaults to just testing if the object is a
* [K] instance.
*
+ * Example:
+ *
+ * new LinkedHashMap<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 [LinkedHashMap.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
@@ -50,19 +69,18 @@ abstract class LinkedHashMap<K, V> implements HashMap<K, V> {
*
* 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 [LinkedHashMap.identity]).
*/
- external factory LinkedHashMap({ bool equals(K key1, K key2),
- int hashCode(K key),
- bool isValidKey(potentialKey) });
+ external factory LinkedHashMap({bool equals(K key1, K key2),
+ int hashCode(K key),
+ bool isValidKey(potentialKey)});
/**
* Creates an insertion-ordered identity-based map.
*
* Effectively a shorthand for:
*
- * new LinkedHashMap(equals: identical, hashCode: identityHashCodeOf)
+ * new LinkedHashMap(equals: identical,
+ * hashCode: identityHashCodeOf)
*/
external factory LinkedHashMap.identity();
« no previous file with comments | « sdk/lib/collection/hash_set.dart ('k') | sdk/lib/collection/linked_hash_set.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698