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

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

Issue 1104063002: Make EfficientLength public, as EfficientLengthIterable. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Tweak documentation. Created 5 years, 8 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.core; 5 part of dart.core;
6 6
7 /** 7 /**
8 * A collection of values, or "elements", that can be accessed sequentially. 8 * A collection of values, or "elements", that can be accessed sequentially.
9 * 9 *
10 * The elements of the iterable are accessed by getting an [Iterator] 10 * The elements of the iterable are accessed by getting an [Iterator]
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 Set<E> toSet() => new Set<E>.from(this); 340 Set<E> toSet() => new Set<E>.from(this);
341 341
342 /** 342 /**
343 * Returns the number of elements in [this]. 343 * Returns the number of elements in [this].
344 * 344 *
345 * Counting all elements may involve iterating through all elements and can 345 * Counting all elements may involve iterating through all elements and can
346 * therefore be slow. 346 * therefore be slow.
347 * Some iterables have a more efficient way to find the number of elements. 347 * Some iterables have a more efficient way to find the number of elements.
348 */ 348 */
349 int get length { 349 int get length {
350 assert(this is! EfficientLength); 350 assert(this is! EfficientLengthIterable);
351 int count = 0; 351 int count = 0;
352 Iterator it = iterator; 352 Iterator it = iterator;
353 while (it.moveNext()) { 353 while (it.moveNext()) {
354 count++; 354 count++;
355 } 355 }
356 return count; 356 return count;
357 } 357 }
358 358
359 /** 359 /**
360 * Returns `true` if there are no elements in this collection. 360 * Returns `true` if there are no elements in this collection.
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 * The conversion may omit calling `toString` on some elements if they 587 * The conversion may omit calling `toString` on some elements if they
588 * are known to not occur in the output, and it may stop iterating after 588 * are known to not occur in the output, and it may stop iterating after
589 * a hundred elements. 589 * a hundred elements.
590 */ 590 */
591 String toString() => IterableBase.iterableToShortString(this, '(', ')'); 591 String toString() => IterableBase.iterableToShortString(this, '(', ')');
592 } 592 }
593 593
594 typedef E _Generator<E>(int index); 594 typedef E _Generator<E>(int index);
595 595
596 class _GeneratorIterable<E> extends Iterable<E> 596 class _GeneratorIterable<E> extends Iterable<E>
597 implements EfficientLength { 597 implements EfficientLengthIterable<E> {
598 final int _start; 598 final int _start;
599 final int _end; 599 final int _end;
600 final _Generator<E> _generator; 600 final _Generator<E> _generator;
601 _GeneratorIterable(this._end, E generator(int n)) 601 _GeneratorIterable(this._end, E generator(int n))
602 : _start = 0, 602 : _start = 0,
603 _generator = (generator != null) ? generator : _id; 603 _generator = (generator != null) ? generator : _id;
604 604
605 _GeneratorIterable.slice(this._start, this._end, this._generator); 605 _GeneratorIterable.slice(this._start, this._end, this._generator);
606 606
607 Iterator<E> get iterator => 607 Iterator<E> get iterator =>
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 */ 654 */
655 abstract class BidirectionalIterator<E> implements Iterator<E> { 655 abstract class BidirectionalIterator<E> implements Iterator<E> {
656 /** 656 /**
657 * Move back to the previous element. 657 * Move back to the previous element.
658 * 658 *
659 * Returns true and updates [current] if successful. Returns false 659 * Returns true and updates [current] if successful. Returns false
660 * and sets [current] to null if there is no previous element. 660 * and sets [current] to null if there is no previous element.
661 */ 661 */
662 bool movePrevious(); 662 bool movePrevious();
663 } 663 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698