OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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.core; | 5 part of dart.core; |
6 | 6 |
7 /** | 7 /** |
8 * A collection of objects in which each object can occur only once. | 8 * A collection of objects in which each object can occur only once. |
9 * | 9 * |
10 * That is, for each object of the element type, the object is either considered | 10 * That is, for each object of the element type, the object is either considered |
11 * to be in the set, or to _not_ be in the set. | 11 * to be in the set, or to _not_ be in the set. |
12 * | 12 * |
13 * Set implementations may consider some elements indistinguishable. These | 13 * Set implementations may consider some elements indistinguishable. These |
14 * elements are treated as being the same for any operation on the set. | 14 * elements are treated as being the same for any operation on the set. |
15 * | 15 * |
16 * The default `Set` implementation, [HashSet], considers objects | 16 * The default `Set` implementation, [HashSet], considers objects |
17 * indistinguishable if they are equal with regard to [Object.operator==]. | 17 * indistinguishable if they are equal with regard to [Object.operator==]. |
18 * | 18 * |
19 * Sets may be either ordered or unordered. [HashSet] is unordered and doesn't | 19 * Sets may be either ordered or unordered. [HashSet] is unordered and doesn't |
20 * guarantee anything about the order that elements are accessed in by | 20 * guarantee anything about the order that elements are accessed in by |
21 * iteration. [LinkedHashSet] iterates in the insertion order of its elements. | 21 * iteration. [LinkedHashSet] iterates in the insertion order of its elements. |
22 */ | 22 */ |
23 abstract class Set<E> extends IterableBase<E> { | 23 abstract class Set<E> extends IterableBase<E> { |
24 /** | 24 /** |
25 * Creates an empty [Set]. | 25 * Creates an empty [Set]. |
26 * | 26 * |
27 * The created `Set` is a [HashSet]. As such, it considers elements that | 27 * The created `Set` is a [LinkedHashSet]. As such, it considers elements that |
28 * are equal (using `==`) to be undistinguishable, and requires them to | 28 * are equal (using `==`) to be indistinguishable, and requires them to |
29 * have a compatible [Object.hashCode] implementation. | 29 * have a compatible [Object.hashCode] implementation. |
30 */ | 30 */ |
31 factory Set() => new HashSet<E>(); | 31 factory Set() = LinkedHashSet<E>; |
| 32 |
| 33 /** |
| 34 * Creates an empty identity [Set]. |
| 35 * |
| 36 * The created `Set` is a [LinkedHashSet] that uses identity as equality |
| 37 * relation. |
| 38 */ |
| 39 factory Set.identity() = LinkedHashSet<E>.identity; |
32 | 40 |
33 /** | 41 /** |
34 * Creates a [Set] that contains all elements of [other]. | 42 * Creates a [Set] that contains all elements of [other]. |
35 * | 43 * |
36 * The created `Set` is a [HashSet]. As such, it considers elements that | 44 * The created `Set` is a [HashSet]. As such, it considers elements that |
37 * are equal (using `==`) to be undistinguishable, and requires them to | 45 * are equal (using `==`) to be undistinguishable, and requires them to |
38 * have a compatible [Object.hashCode] implementation. | 46 * have a compatible [Object.hashCode] implementation. |
39 */ | 47 */ |
40 factory Set.from(Iterable<E> other) => new HashSet<E>.from(other); | 48 factory Set.from(Iterable<E> other) = LinkedHashSet<E>.from; |
41 | 49 |
42 /** | 50 /** |
43 * Returns true if [value] is in the set. | 51 * Returns true if [value] is in the set. |
44 */ | 52 */ |
45 bool contains(Object value); | 53 bool contains(Object value); |
46 | 54 |
47 /** | 55 /** |
48 * Adds [value] into the set. | 56 * Adds [value] into the set. |
49 * | 57 * |
50 * The method has no effect if [value] is already in the set. | 58 * The method has no effect if [value] is already in the set. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 * That is, the returned set contains all the elements of this `Set` that | 121 * That is, the returned set contains all the elements of this `Set` that |
114 * are not elements of [other]. | 122 * are not elements of [other]. |
115 */ | 123 */ |
116 Set<E> difference(Set<E> other); | 124 Set<E> difference(Set<E> other); |
117 | 125 |
118 /** | 126 /** |
119 * Removes all elements in the set. | 127 * Removes all elements in the set. |
120 */ | 128 */ |
121 void clear(); | 129 void clear(); |
122 } | 130 } |
OLD | NEW |