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

Side by Side Diff: sdk/lib/collection/hash_set.dart

Issue 838463002: Change List/Set/Map/Queue.from constructrs to accept any iterable. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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
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 /** Common parts of [HashSet] and [LinkedHashSet] implementations. */ 7 /** Common parts of [HashSet] and [LinkedHashSet] implementations. */
8 abstract class _HashSetBase<E> extends SetBase<E> { 8 abstract class _HashSetBase<E> extends SetBase<E> {
9 9
10 // The following two methods override the ones in SetBase. 10 // The following two methods override the ones in SetBase.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 * the objects' intrinsic [Object.operator==] and [Object.hashCode]. 64 * the objects' intrinsic [Object.operator==] and [Object.hashCode].
65 * 65 *
66 * If [isValidKey] is omitted, it defaults to testing if the object is an 66 * If [isValidKey] is omitted, it defaults to testing if the object is an
67 * [E] instance. 67 * [E] instance.
68 * 68 *
69 * If you supply one of [equals] and [hashCode], 69 * If you supply one of [equals] and [hashCode],
70 * you should generally also to supply the other. 70 * you should generally also to supply the other.
71 * An example would be using [identical] and [identityHashCode], 71 * An example would be using [identical] and [identityHashCode],
72 * which is equivalent to using the shorthand [LinkedSet.identity]). 72 * which is equivalent to using the shorthand [LinkedSet.identity]).
73 */ 73 */
74 external factory HashSet({ bool equals(E e1, E e2), 74 external factory HashSet({bool equals(E e1, E e2),
75 int hashCode(E e), 75 int hashCode(E e),
76 bool isValidKey(potentialKey) }); 76 bool isValidKey(potentialKey)});
77 77
78 /** 78 /**
79 * Creates an unordered identity-based set. 79 * Creates an unordered identity-based set.
80 * 80 *
81 * Effectively a shorthand for: 81 * Effectively a shorthand for:
82 * 82 *
83 * new HashSet(equals: identical, hashCode: identityHashCodeOf) 83 * new HashSet(equals: identical, hashCode: identityHashCodeOf)
84 */ 84 */
85 external factory HashSet.identity(); 85 external factory HashSet.identity();
86 86
87 /** 87 /**
88 * Create a hash set containing the elements of [iterable]. 88 * Create a hash set containing all of [elements].
floitsch 2015/01/05 14:45:30 all [elements]. ?
Lasse Reichstein Nielsen 2015/01/06 10:14:45 Done.
89 * 89 *
90 * Creates a hash set as by `new HashSet<E>()` and adds each element of 90 * Creates a hash set as by `new HashSet<E>()` and adds each element of
91 * `iterable` to this set in the order they are iterated. 91 * `elements` to this set in the order they are iterated.
92 *
93 * All the [elements] should be assignable to [E].
Søren Gjesse 2015/01/05 15:35:15 [E] -> `E`
Lasse Reichstein Nielsen 2015/01/06 10:14:45 Why? The [E] is in scope, so we might as well link
Søren Gjesse 2015/01/06 12:09:05 Good - I am not exactly clear on the dartdoc scopi
Lasse Reichstein Nielsen 2015/01/07 07:56:45 The spec tries to specify how references in DartDo
94 * The `elements` iterable itself may have any element type, so this
95 * constructor can be used to down-cast a `Set`, for example as:
96 *
97 * Set<SuperType> superSet = ...;
98 * Set<SubType> subSet =
99 * new HashSet<SubType>.from(superSet.where((e) => e is SubType));
92 */ 100 */
93 factory HashSet.from(Iterable<E> iterable) { 101 factory HashSet.from(Iterable elements) {
94 return new HashSet<E>()..addAll(iterable); 102 HashSet<E> result = new HashSet<E>();
103 for (E e in elements) result.add(e);
104 return result;
95 } 105 }
96 106
97 /** 107 /**
98 * Provides an iterator that iterates over the elements of this set. 108 * Provides an iterator that iterates over the elements of this set.
99 * 109 *
100 * The order of iteration is unspecified, 110 * The order of iteration is unspecified,
101 * but consistent between changes to the set. 111 * but consistent between changes to the set.
102 */ 112 */
103 Iterator<E> get iterator; 113 Iterator<E> get iterator;
104 } 114 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698