Chromium Code Reviews| Index: sdk/lib/collection/hash_map.dart |
| diff --git a/sdk/lib/collection/hash_map.dart b/sdk/lib/collection/hash_map.dart |
| index a0624e005a9ebd018444621d8229ee6840053006..91cc1f51a08d0648bf3b84f9d2b53578def476a1 100644 |
| --- a/sdk/lib/collection/hash_map.dart |
| +++ b/sdk/lib/collection/hash_map.dart |
| @@ -4,6 +4,11 @@ |
| part of dart.collection; |
| +/** Default function for equality comparison in customized HashMaps */ |
| +bool _defaultEquals(a, b) => a == b; |
| +/** Default function for hash-code computation in customized HashMaps */ |
| +int _defaultHashCode(a) => a.hashCode; |
| + |
| /** |
| * A hash-table based implementation of [Map]. |
| * |
| @@ -16,7 +21,37 @@ part of dart.collection; |
| * The map allows `null` as a key. |
| */ |
| class HashMap<K, V> implements Map<K, V> { |
| - external HashMap(); |
| + /** |
| + * Creates an unordered hash-table based [Map]. |
|
floitsch
2013/09/03 11:19:49
I'm not sure I like the word "unordered" here.
Don
Lasse Reichstein Nielsen
2013/09/03 11:44:28
Done.
|
| + * |
| + * If [equals] is provided, it is used to compare the keys in the table with |
| + * new keys. If [equals] is omitted, the key's own [Object.operator==] is used |
| + * instead. |
| + * |
| + * Similar, if [hashCode] is provided, it is used to produce a hash value |
| + * for keys in order to place them in the hash table. If it is omitted, the |
| + * key's own [Object.hashCode] is used. |
| + * |
| + * 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. |
| + */ |
| + factory HashMap({bool equals(K key1, K key2), int hashCode(K key)}) { |
| + if (equals != null || hashCode != null) { |
| + if (equals == null) { |
| + equals = _defaultEquals; |
| + } else if (hashCode == null) { |
| + hashCode = _defaultHashCode; |
| + } |
| + // Create new CustomHashMap<K, V>(equals, hashCode). |
| + throw new UnimplementedError("Not implemented yet"); |
| + } |
| + return new HashMap<K, V>._internal(); |
| + } |
| + |
| + /** Creates an empty `HashMap` with the default equals and hashCode. */ |
| + external HashMap._internal(); |
| /** |
| * Creates a [HashMap] that contains all key value pairs of [other]. |