OLD | NEW |
---|---|
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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 * Effectively a shorthand for: | 101 * Effectively a shorthand for: |
102 * | 102 * |
103 * new HashSet<E>(equals: identical, | 103 * new HashSet<E>(equals: identical, |
104 * hashCode: identityHashCode) | 104 * hashCode: identityHashCode) |
105 */ | 105 */ |
106 external factory HashSet.identity(); | 106 external factory HashSet.identity(); |
107 | 107 |
108 /** | 108 /** |
109 * Create a hash set containing all [elements]. | 109 * Create a hash set containing all [elements]. |
110 * | 110 * |
111 * Creates a hash set as by `new HashSet<E>()` and adds each element of | 111 * Creates a hash set as by `new HashSet<E>()` and adds all given [elements] |
112 * `elements` to this set in the order they are iterated. | 112 * to the set. The elements are added in order. If [elements] contains |
113 * two entries that are equal, but not identical, then the first one is | |
114 * the one in the resulting set. | |
Lasse Reichstein Nielsen
2016/12/13 14:01:33
Good idea.
floitsch
2016/12/13 14:08:31
Acknowledged.
| |
115 * | |
116 * The iteration order of the resulting set is undetermined and depends on | |
Lasse Reichstein Nielsen
2016/12/13 14:01:33
I don't think we have used "undetermined" anywhere
floitsch
2016/12/13 14:08:31
not specified.
| |
117 * the hashcodes of the provided elements. However, the order is stable: | |
118 * multiple iterations over the same set produce the same order, as long as | |
119 * the set is not modified. | |
Lasse Reichstein Nielsen
2016/12/13 14:01:33
I'm not sure we need to repeat what unordered set
floitsch
2016/12/13 14:08:31
Done.
| |
113 * | 120 * |
114 * All the [elements] should be assignable to [E]. | 121 * All the [elements] should be assignable to [E]. |
115 * The `elements` iterable itself may have any element type, so this | 122 * The `elements` iterable itself may have any element type, so this |
116 * constructor can be used to down-cast a `Set`, for example as: | 123 * constructor can be used to down-cast a `Set`, for example as: |
117 * | 124 * |
118 * Set<SuperType> superSet = ...; | 125 * Set<SuperType> superSet = ...; |
119 * Set<SubType> subSet = | 126 * Set<SubType> subSet = |
120 * new HashSet<SubType>.from(superSet.where((e) => e is SubType)); | 127 * new HashSet<SubType>.from(superSet.where((e) => e is SubType)); |
121 */ | 128 */ |
122 factory HashSet.from(Iterable elements) { | 129 factory HashSet.from(Iterable elements) { |
123 HashSet<E> result = new HashSet<E>(); | 130 HashSet<E> result = new HashSet<E>(); |
124 for (final e in elements) { | 131 for (final e in elements) { |
125 E element = e as Object/*=E*/; | 132 E element = e as Object/*=E*/; |
126 result.add(element); | 133 result.add(element); |
127 } | 134 } |
128 return result; | 135 return result; |
129 } | 136 } |
130 | 137 |
131 /** | 138 /** |
132 * Provides an iterator that iterates over the elements of this set. | 139 * Provides an iterator that iterates over the elements of this set. |
133 * | 140 * |
134 * The order of iteration is unspecified, | 141 * The order of iteration is unspecified, |
135 * but consistent between changes to the set. | 142 * but consistent between changes to the set. |
136 */ | 143 */ |
137 Iterator<E> get iterator; | 144 Iterator<E> get iterator; |
138 } | 145 } |
OLD | NEW |