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

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

Issue 23872008: Reapply "Make LinkedHashMap also have a factory constructor and be customizable"" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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/_internal/lib/collection_patch.dart ('k') | sdk/lib/collection/linked_hash_map.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/collection/hash_map.dart
diff --git a/sdk/lib/collection/hash_map.dart b/sdk/lib/collection/hash_map.dart
index 3aadab231762b62d3599d4cafce6ff22594dc8b0..bcca966bba5504920f033b4be915596118f83024 100644
--- a/sdk/lib/collection/hash_map.dart
+++ b/sdk/lib/collection/hash_map.dart
@@ -41,6 +41,14 @@ abstract class HashMap<K, V> implements Map<K, V> {
* for keys in order to place them in the hash table. If it is omitted, the
* key's own [Object.hashCode] is used.
*
+ * If using methods like [operator[]], [remove] and [containsKey] together
+ * with a custom equality and hashcode, an extra `isValidKey` function
+ * can be supplied. This function is called before calling [equals] or
+ * [hashCode] with an argument that may not be a [K] instance, and if the
+ * call returns false, the key is assumed to not be in the set.
+ * The [isValidKey] function defaults to just testing if the object is a
+ * [K] instance.
+ *
* 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,7 +58,9 @@ abstract class HashMap<K, V> implements Map<K, V> {
* you also want to supply the other. The only common exception is to pass
* [identical] as the equality and use the default hash code.
*/
- external factory HashMap({bool equals(K key1, K key2), int hashCode(K key)});
+ external factory HashMap({bool equals(K key1, K key2),
+ int hashCode(K key),
+ bool isValidKey(potentialKey)});
/**
* Creates a [HashMap] that contains all key value pairs of [other].
« no previous file with comments | « sdk/lib/_internal/lib/collection_patch.dart ('k') | sdk/lib/collection/linked_hash_map.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698