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

Side by Side Diff: sdk/lib/collection/linked_list.dart

Issue 18837002: Move toString() to collection classes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments. Created 7 years, 5 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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; 5 part of dart.collection;
6 6
7 7
8 /** 8 /**
9 * A linked list implementation, providing O(1) removal(unlink) of elements and 9 * A linked list implementation, providing O(1) removal(unlink) of elements and
10 * manual traversal through [next] and [previous]. 10 * manual traversal through [next] and [previous].
11 * 11 *
12 * The list elements must extend [LinkedListEntry]. 12 * The list elements must extend [LinkedListEntry].
13 */ 13 */
14 class LinkedList<E extends LinkedListEntry<E>> 14 class LinkedList<E extends LinkedListEntry<E>>
15 extends IterableBase<E> 15 extends IterableBase<E>
16 implements _LinkedListLink { 16 implements _LinkedListLink {
17
17 int _modificationCount = 0; 18 int _modificationCount = 0;
18 int _length = 0; 19 int _length = 0;
19 _LinkedListLink _next; 20 _LinkedListLink _next;
20 _LinkedListLink _previous; 21 _LinkedListLink _previous;
21 22
22 /** 23 /**
23 * Construct a new empty linked list. 24 * Construct a new empty linked list.
24 */ 25 */
25 LinkedList() { 26 LinkedList() {
26 _next = _previous = this; 27 _next = _previous = this;
(...skipping 26 matching lines...) Expand all
53 * If [entry] is not in the list, `false` is returned. 54 * If [entry] is not in the list, `false` is returned.
54 */ 55 */
55 bool remove(E entry) { 56 bool remove(E entry) {
56 if (entry._list != this) return false; 57 if (entry._list != this) return false;
57 _unlink(entry); // Unlink will decrement length. 58 _unlink(entry); // Unlink will decrement length.
58 return true; 59 return true;
59 } 60 }
60 61
61 Iterator<E> get iterator => new _LinkedListIterator<E>(this); 62 Iterator<E> get iterator => new _LinkedListIterator<E>(this);
62 63
63 String toString() => ToString.iterableToString(this); 64 //TODO Remove this, and let it be inherited by IterableMixin
floitsch 2013/07/08 16:12:34 Add space after "//". TODOS are always of the form
zarah 2013/07/08 16:57:46 Done.
65 String toString() => IterableMixinWorkaround.toStringIterable(this);
64 66
65 int get length => _length; 67 int get length => _length;
66 68
67 void clear() { 69 void clear() {
68 _modificationCount++; 70 _modificationCount++;
69 _LinkedListLink next = _next; 71 _LinkedListLink next = _next;
70 while (!identical(next, this)) { 72 while (!identical(next, this)) {
71 E entry = next; 73 E entry = next;
72 next = entry._next; 74 next = entry._next;
73 entry._next = entry._previous = entry._list = null; 75 entry._next = entry._previous = entry._list = null;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 _list._insertAfter(this, entry); 225 _list._insertAfter(this, entry);
224 } 226 }
225 227
226 /** 228 /**
227 * Insert an element before this. 229 * Insert an element before this.
228 */ 230 */
229 void insertBefore(E entry) { 231 void insertBefore(E entry) {
230 _list._insertAfter(_previous, entry); 232 _list._insertAfter(_previous, entry);
231 } 233 }
232 } 234 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698