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

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

Issue 26681002: Add EfficientLength marker interface to some iterabels. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Also document Map.length is efficient, while we are at it. Created 7 years, 2 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/map.dart ('k') | sdk/lib/utf/utf.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 * 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> implements EfficientLength {
24 /** 24 /**
25 * Creates an empty [Set]. 25 * Creates an empty [Set].
26 * 26 *
27 * The created `Set` is a [LinkedHashSet]. 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 indistinguishable, 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() = LinkedHashSet<E>; 31 factory Set() = LinkedHashSet<E>;
32 32
33 /** 33 /**
34 * Creates an empty identity [Set]. 34 * Creates an empty identity [Set].
35 * 35 *
36 * The created `Set` is a [LinkedHashSet] that uses identity as equality 36 * The created `Set` is a [LinkedHashSet] that uses identity as equality
37 * relation. 37 * relation.
38 */ 38 */
39 factory Set.identity() = LinkedHashSet<E>.identity; 39 factory Set.identity() = LinkedHashSet<E>.identity;
40 40
41 /** 41 /**
42 * Creates a [Set] that contains all elements of [other]. 42 * Creates a [Set] that contains all elements of [other].
43 * 43 *
44 * 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
45 * are equal (using `==`) to be undistinguishable, and requires them to 45 * are equal (using `==`) to be undistinguishable, and requires them to
46 * have a compatible [Object.hashCode] implementation. 46 * have a compatible [Object.hashCode] implementation.
47 */ 47 */
48 factory Set.from(Iterable<E> other) = LinkedHashSet<E>.from; 48 factory Set.from(Iterable<E> other) = LinkedHashSet<E>.from;
49 49
50 /** 50 /**
51 * Returns the number of elements in this set.
52 *
53 * This operation is efficient, and does not require iterating and counting
54 * the elements.
55 */
56 int get length;
57
58 /**
51 * Returns true if [value] is in the set. 59 * Returns true if [value] is in the set.
52 */ 60 */
53 bool contains(Object value); 61 bool contains(Object value);
54 62
55 /** 63 /**
56 * Adds [value] into the set. 64 * Adds [value] into the set.
57 * 65 *
58 * The method has no effect if [value] is already in the set. 66 * The method has no effect if [value] is already in the set.
59 */ 67 */
60 void add(E value); 68 void add(E value);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 * That is, the returned set contains all the elements of this `Set` that 129 * That is, the returned set contains all the elements of this `Set` that
122 * are not elements of [other]. 130 * are not elements of [other].
123 */ 131 */
124 Set<E> difference(Set<E> other); 132 Set<E> difference(Set<E> other);
125 133
126 /** 134 /**
127 * Removes all elements in the set. 135 * Removes all elements in the set.
128 */ 136 */
129 void clear(); 137 void clear();
130 } 138 }
OLDNEW
« no previous file with comments | « sdk/lib/core/map.dart ('k') | sdk/lib/utf/utf.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698