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/_collection_dev/iterable.dart

Issue 12391010: Make HashSet.length constant time. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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) 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._collection.dev; 5 part of dart._collection.dev;
6 6
7 /** 7 /**
8 * An [Iterable] for classes that have efficient [length] and [elementAt]. 8 * An [Iterable] for classes that have efficient [length] and [elementAt].
9 * 9 *
10 * All other methods are implemented in terms of [length] and [elementAt], 10 * All other methods are implemented in terms of [length] and [elementAt],
(...skipping 10 matching lines...) Expand all
21 void forEach(void action(E element)) { 21 void forEach(void action(E element)) {
22 int length = this.length; 22 int length = this.length;
23 for (int i = 0; i < length; i++) { 23 for (int i = 0; i < length; i++) {
24 action(elementAt(i)); 24 action(elementAt(i));
25 if (length != this.length) { 25 if (length != this.length) {
26 throw new ConcurrentModificationError(this); 26 throw new ConcurrentModificationError(this);
27 } 27 }
28 } 28 }
29 } 29 }
30 30
31 bool get isEmpty => length != 0; 31 bool get isEmpty => length == 0;
32 32
33 E get first { 33 E get first {
34 if (length == 0) throw new StateError("No elements"); 34 if (length == 0) throw new StateError("No elements");
35 return elementAt(0); 35 return elementAt(0);
36 } 36 }
37 37
38 E get last { 38 E get last {
39 if (length == 0) throw new StateError("No elements"); 39 if (length == 0) throw new StateError("No elements");
40 return elementAt(length - 1); 40 return elementAt(length - 1);
41 } 41 }
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 class EmptyIterator<E> implements Iterator<E> { 690 class EmptyIterator<E> implements Iterator<E> {
691 const EmptyIterator(); 691 const EmptyIterator();
692 bool moveNext() => false; 692 bool moveNext() => false;
693 E get current => null; 693 E get current => null;
694 } 694 }
695 695
696 /** An [Iterator] that can move in both directions. */ 696 /** An [Iterator] that can move in both directions. */
697 abstract class BidirectionalIterator<T> implements Iterator<T> { 697 abstract class BidirectionalIterator<T> implements Iterator<T> {
698 bool movePrevious(); 698 bool movePrevious();
699 } 699 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/collection/hash_set.dart » ('j') | tests/corelib/collection_length_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698