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

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

Issue 18282008: Revert "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
« no previous file with comments | « sdk/lib/collection/hash_set.dart ('k') | sdk/lib/collection/list.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) 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
18 int _modificationCount = 0; 17 int _modificationCount = 0;
19 int _length = 0; 18 int _length = 0;
20 _LinkedListLink _next; 19 _LinkedListLink _next;
21 _LinkedListLink _previous; 20 _LinkedListLink _previous;
22 21
23 /** 22 /**
24 * Construct a new empty linked list. 23 * Construct a new empty linked list.
25 */ 24 */
26 LinkedList() { 25 LinkedList() {
27 _next = _previous = this; 26 _next = _previous = this;
(...skipping 26 matching lines...) Expand all
54 * If [entry] is not in the list, `false` is returned. 53 * If [entry] is not in the list, `false` is returned.
55 */ 54 */
56 bool remove(E entry) { 55 bool remove(E entry) {
57 if (entry._list != this) return false; 56 if (entry._list != this) return false;
58 _unlink(entry); // Unlink will decrement length. 57 _unlink(entry); // Unlink will decrement length.
59 return true; 58 return true;
60 } 59 }
61 60
62 Iterator<E> get iterator => new _LinkedListIterator<E>(this); 61 Iterator<E> get iterator => new _LinkedListIterator<E>(this);
63 62
64 // TODO(zarah) Remove this, and let it be inherited by IterableMixin 63 String toString() => ToString.iterableToString(this);
65 String toString() => IterableMixinWorkaround.toStringIterable(this, '{', '}');
66 64
67 int get length => _length; 65 int get length => _length;
68 66
69 void clear() { 67 void clear() {
70 _modificationCount++; 68 _modificationCount++;
71 _LinkedListLink next = _next; 69 _LinkedListLink next = _next;
72 while (!identical(next, this)) { 70 while (!identical(next, this)) {
73 E entry = next; 71 E entry = next;
74 next = entry._next; 72 next = entry._next;
75 entry._next = entry._previous = entry._list = null; 73 entry._next = entry._previous = entry._list = null;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 _list._insertAfter(this, entry); 223 _list._insertAfter(this, entry);
226 } 224 }
227 225
228 /** 226 /**
229 * Insert an element before this. 227 * Insert an element before this.
230 */ 228 */
231 void insertBefore(E entry) { 229 void insertBefore(E entry) {
232 _list._insertAfter(_previous, entry); 230 _list._insertAfter(_previous, entry);
233 } 231 }
234 } 232 }
OLDNEW
« no previous file with comments | « sdk/lib/collection/hash_set.dart ('k') | sdk/lib/collection/list.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698