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

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

Issue 23494027: Make LinkedHashMap also have a factory constructor and be customizable (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add isValidKey. 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
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..6829892eee0aac1937f17d461e9b53bbf9bc2492 100644
--- a/sdk/lib/collection/hash_map.dart
+++ b/sdk/lib/collection/hash_map.dart
@@ -41,6 +41,19 @@ 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 [isValidKey] method is ignored if `equals` and `hashCode`
floitsch 2013/09/06 12:33:20 Let's not do that. If supplied it should be called
Lasse Reichstein Nielsen 2013/09/06 12:52:11 Done.
+ * are both omitted, or if `equals` is the [identical] function and
+ * `hashcode` is omitted, because in those cases, the `equals` and `hashCode`
+ * functions are known to apply to all arguments.
+ *
* 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 +63,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].

Powered by Google App Engine
This is Rietveld 408576698