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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.collection; 5 part of dart.collection;
6 6
7 /** Default function for equality comparison in customized HashMaps */ 7 /** Default function for equality comparison in customized HashMaps */
8 bool _defaultEquals(a, b) => a == b; 8 bool _defaultEquals(a, b) => a == b;
9 /** Default function for hash-code computation in customized HashMaps */ 9 /** Default function for hash-code computation in customized HashMaps */
10 int _defaultHashCode(a) => a.hashCode; 10 int _defaultHashCode(a) => a.hashCode;
(...skipping 23 matching lines...) Expand all
34 * same as long as the map isn't changed. 34 * same as long as the map isn't changed.
35 * 35 *
36 * If [equals] is provided, it is used to compare the keys in the table with 36 * If [equals] is provided, it is used to compare the keys in the table with
37 * new keys. If [equals] is omitted, the key's own [Object.operator==] is used 37 * new keys. If [equals] is omitted, the key's own [Object.operator==] is used
38 * instead. 38 * instead.
39 * 39 *
40 * Similar, if [hashCode] is provided, it is used to produce a hash value 40 * Similar, if [hashCode] is provided, it is used to produce a hash value
41 * for keys in order to place them in the hash table. If it is omitted, the 41 * for keys in order to place them in the hash table. If it is omitted, the
42 * key's own [Object.hashCode] is used. 42 * key's own [Object.hashCode] is used.
43 * 43 *
44 * If using methods like [operator[]], [remove] and [containsKey] together
45 * with a custom equality and hashcode, an extra `isValidKey` function
46 * can be supplied. This function is called before calling [equals] or
47 * [hashCode] with an argument that may not be a [K] instance, and if the
48 * call returns false, the key is assumed to not be in the set.
49 * The [isValidKey] function defaults to just testing if the object is a
50 * [K] instance.
51 *
44 * The used `equals` and `hashCode` method should always be consistent, 52 * The used `equals` and `hashCode` method should always be consistent,
45 * so that if `equals(a, b)` then `hashCode(a) == hashCode(b)`. The hash 53 * so that if `equals(a, b)` then `hashCode(a) == hashCode(b)`. The hash
46 * of an object, or what it compares equal to, should not change while the 54 * of an object, or what it compares equal to, should not change while the
47 * object is in the table. If it does change, the result is unpredictable. 55 * object is in the table. If it does change, the result is unpredictable.
48 * 56 *
49 * It is generally the case that if you supply one of [equals] and [hashCode], 57 * It is generally the case that if you supply one of [equals] and [hashCode],
50 * you also want to supply the other. The only common exception is to pass 58 * you also want to supply the other. The only common exception is to pass
51 * [identical] as the equality and use the default hash code. 59 * [identical] as the equality and use the default hash code.
52 */ 60 */
53 external factory HashMap({bool equals(K key1, K key2), int hashCode(K key)}); 61 external factory HashMap({bool equals(K key1, K key2),
62 int hashCode(K key),
63 bool isValidKey(potentialKey)});
54 64
55 /** 65 /**
56 * Creates a [HashMap] that contains all key value pairs of [other]. 66 * Creates a [HashMap] that contains all key value pairs of [other].
57 */ 67 */
58 factory HashMap.from(Map<K, V> other) { 68 factory HashMap.from(Map<K, V> other) {
59 return new HashMap<K, V>()..addAll(other); 69 return new HashMap<K, V>()..addAll(other);
60 } 70 }
61 71
62 /** 72 /**
63 * Creates a [HashMap] where the keys and values are computed from the 73 * Creates a [HashMap] where the keys and values are computed from the
(...skipping 25 matching lines...) Expand all
89 * overwrites the previous value. 99 * overwrites the previous value.
90 * 100 *
91 * It is an error if the two [Iterable]s don't have the same length. 101 * It is an error if the two [Iterable]s don't have the same length.
92 */ 102 */
93 factory HashMap.fromIterables(Iterable<K> keys, Iterable<V> values) { 103 factory HashMap.fromIterables(Iterable<K> keys, Iterable<V> values) {
94 HashMap<K, V> map = new HashMap<K, V>(); 104 HashMap<K, V> map = new HashMap<K, V>();
95 Maps._fillMapWithIterables(map, keys, values); 105 Maps._fillMapWithIterables(map, keys, values);
96 return map; 106 return map;
97 } 107 }
98 } 108 }
OLDNEW
« 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