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

Side by Side Diff: sdk/lib/core/set.dart

Issue 16285004: Better documentation on Sets and Maps, and more. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 6 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/core/num.dart ('k') | sdk/lib/core/string.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) 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 * This class is the public interface of a set. A set is a collection 8 * A `Set` is a collection of elements where each element can occur only once.
9 * without duplicates. 9 *
10 * That is, for each object of the element type, the object is either considered
11 * to be in the set, or it is not in the set.
12 *
13 * Set implementations may consider some elements indistinguishable. These
14 * objects will be treated as being the same for any operation on the set.
15 *
16 * The default `Set` implementation, [HashSet], considers objects
17 * indistinguishable if they are equal with regard to [Object.operator==].
18 *
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
21 * iteration. [LinkedHashSet] iterates in the insertion order of its elements.
10 */ 22 */
11 abstract class Set<E> extends IterableBase<E> { 23 abstract class Set<E> extends IterableBase<E> {
24 /**
25 * Creates an empty [Set].
26 *
27 * The created `Set` is a [HashSet]. As such, it considers elements that
28 * are equal (using `==`) to be undistinguishable, and requires them to
29 * have a compatible [Object.hashCode] implementation.
30 */
12 factory Set() => new HashSet<E>(); 31 factory Set() => new HashSet<E>();
13 32
14 /** 33 /**
15 * Creates a [Set] that contains all elements of [other]. 34 * Creates a [Set] that contains all elements of [other].
35 *
36 * The created `Set` is a [HashSet]. As such, it considers elements that
37 * are equal (using `==`) to be undistinguishable, and requires them to
38 * have a compatible [Object.hashCode] implementation.
16 */ 39 */
17 factory Set.from(Iterable<E> other) => new HashSet<E>.from(other); 40 factory Set.from(Iterable<E> other) => new HashSet<E>.from(other);
18 41
19 /** 42 /**
20 * Returns true if [value] is in the set. 43 * Returns true if [value] is in the set.
21 */ 44 */
22 bool contains(E value); 45 bool contains(E value);
23 46
24 /** 47 /**
25 * Adds [value] into the set. The method has no effect if 48 * Adds [value] into the set.
26 * [value] was already in the set. 49 *
50 * The method has no effect if [value] is already in the set.
27 */ 51 */
28 void add(E value); 52 void add(E value);
29 53
30 /** 54 /**
31 * Adds all of [elements] to this Set. 55 * Adds all of [elements] to this Set.
32 * 56 *
33 * Equivalent to adding each element in [elements] using [add], 57 * Equivalent to adding each element in [elements] using [add],
34 * but some collections may be able to optimize it. 58 * but some collections may be able to optimize it.
35 */ 59 */
36 void addAll(Iterable<E> elements); 60 void addAll(Iterable<E> elements);
37 61
38 /** 62 /**
39 * Removes [value] from the set. Returns true if [value] was 63 * Removes [value] from the set. Returns true if [value] was
40 * in the set. Returns false otherwise. The method has no effect 64 * in the set. Returns false otherwise. The method has no effect
41 * if [value] value was not in the set. 65 * if [value] value was not in the set.
42 */ 66 */
43 bool remove(Object value); 67 bool remove(Object value);
44 68
45 /** 69 /**
46 * Removes all of [elements] from this set. 70 * Removes each element of [elements] from this set.
47 */ 71 */
48 void removeAll(Iterable elements); 72 void removeAll(Iterable elements);
49 73
50 /** 74 /**
51 * Removes all elements of this set that are not 75 * Removes all elements of this set that are not elements in [elements].
52 * in [elements].
53 */ 76 */
54 void retainAll(Iterable elements); 77 void retainAll(Iterable elements);
55 78
56 /** 79 /**
57 * Removes all elements of this set that satisfy [test]. 80 * Removes all elements of this set that satisfy [test].
58 */ 81 */
59 void removeWhere(bool test(E element)); 82 void removeWhere(bool test(E element));
60 83
61 /** 84 /**
62 * Removes all elements of this set that fail to satisfy [test]. 85 * Removes all elements of this set that fail to satisfy [test].
63 */ 86 */
64 void retainWhere(bool test(E element)); 87 void retainWhere(bool test(E element));
65 88
66 /** 89 /**
67 * Returns true if this Set contains all the elements of [other]. 90 * Returns whether this Set contains all the elements of [other].
68 */ 91 */
69 bool containsAll(Iterable<E> other); 92 bool containsAll(Iterable<E> other);
70 93
71 /** 94 /**
72 * Returns a new set which is the intersection between this set and [other]. 95 * Returns a new set which is the intersection between this set and [other].
96 *
97 * That is, the returned set contains all the elements of this `Set` that
98 * are also elements of [other].
73 */ 99 */
74 Set<E> intersection(Set<E> other); 100 Set<E> intersection(Set<E> other);
75 101
76 /** 102 /**
77 * Returns a new set which contains all the elements of this set and [other]. 103 * Returns a new set which contains all the elements of this set and [other].
104 *
105 * That is, the returned set contains all the elements of this `Set` and
106 * all the elements of [other].
78 */ 107 */
79 Set<E> union(Set<E> other); 108 Set<E> union(Set<E> other);
80 109
81 /** 110 /**
82 * Returns a new set with the the elements of this that are not in [other]. 111 * Returns a new set with the the elements of this that are not in [other].
112 *
113 * That is, the returned set contains all the elements of this `Set` that
114 * are not elements of [other].
83 */ 115 */
84 Set<E> difference(Set<E> other); 116 Set<E> difference(Set<E> other);
85 117
86 /** 118 /**
87 * Removes all elements in the set. 119 * Removes all elements in the set.
88 */ 120 */
89 void clear(); 121 void clear();
90 } 122 }
OLDNEW
« no previous file with comments | « sdk/lib/core/num.dart ('k') | sdk/lib/core/string.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698