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

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: 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 static List _toStringList = new List();
18
17 int _modificationCount = 0; 19 int _modificationCount = 0;
18 int _length = 0; 20 int _length = 0;
19 _LinkedListLink _next; 21 _LinkedListLink _next;
20 _LinkedListLink _previous; 22 _LinkedListLink _previous;
21 23
22 /** 24 /**
23 * Construct a new empty linked list. 25 * Construct a new empty linked list.
24 */ 26 */
25 LinkedList() { 27 LinkedList() {
26 _next = _previous = this; 28 _next = _previous = this;
(...skipping 26 matching lines...) Expand all
53 * If [entry] is not in the list, `false` is returned. 55 * If [entry] is not in the list, `false` is returned.
54 */ 56 */
55 bool remove(E entry) { 57 bool remove(E entry) {
56 if (entry._list != this) return false; 58 if (entry._list != this) return false;
57 _unlink(entry); // Unlink will decrement length. 59 _unlink(entry); // Unlink will decrement length.
58 return true; 60 return true;
59 } 61 }
60 62
61 Iterator<E> get iterator => new _LinkedListIterator<E>(this); 63 Iterator<E> get iterator => new _LinkedListIterator<E>(this);
62 64
63 String toString() => ToString.iterableToString(this); 65 String toString() {
66 for(int i = 0; i < _toStringList.length; i++) {
floitsch 2013/07/08 12:00:50 Simple call to IterableMixinWorkaround. Add TODO t
zarah 2013/07/08 14:35:15 Done.
67 if(identical(_toStringList[i], this))
68 return '{...}';
69 }
70 _toStringList.add(this);
71 String result = IterableMixinWorkaround.toStringIterable(this);
72 _toStringList.remove(this);
73 return result;
74 }
64 75
65 int get length => _length; 76 int get length => _length;
66 77
67 void clear() { 78 void clear() {
68 _modificationCount++; 79 _modificationCount++;
69 _LinkedListLink next = _next; 80 _LinkedListLink next = _next;
70 while (!identical(next, this)) { 81 while (!identical(next, this)) {
71 E entry = next; 82 E entry = next;
72 next = entry._next; 83 next = entry._next;
73 entry._next = entry._previous = entry._list = null; 84 entry._next = entry._previous = entry._list = null;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 _list._insertAfter(this, entry); 234 _list._insertAfter(this, entry);
224 } 235 }
225 236
226 /** 237 /**
227 * Insert an element before this. 238 * Insert an element before this.
228 */ 239 */
229 void insertBefore(E entry) { 240 void insertBefore(E entry) {
230 _list._insertAfter(_previous, entry); 241 _list._insertAfter(_previous, entry);
231 } 242 }
232 } 243 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698