OLD | NEW |
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]. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 * If [entry] is not in the list, `false` is returned. | 54 * If [entry] is not in the list, `false` is returned. |
55 */ | 55 */ |
56 bool remove(E entry) { | 56 bool remove(E entry) { |
57 if (entry._list != this) return false; | 57 if (entry._list != this) return false; |
58 _unlink(entry); // Unlink will decrement length. | 58 _unlink(entry); // Unlink will decrement length. |
59 return true; | 59 return true; |
60 } | 60 } |
61 | 61 |
62 Iterator<E> get iterator => new _LinkedListIterator<E>(this); | 62 Iterator<E> get iterator => new _LinkedListIterator<E>(this); |
63 | 63 |
64 // TODO(zarah) Remove this, and let it be inherited by IterableMixin | |
65 String toString() => IterableMixinWorkaround.toStringIterable(this, '{', '}'); | |
66 | |
67 int get length => _length; | 64 int get length => _length; |
68 | 65 |
69 void clear() { | 66 void clear() { |
70 _modificationCount++; | 67 _modificationCount++; |
71 _LinkedListLink next = _next; | 68 _LinkedListLink next = _next; |
72 while (!identical(next, this)) { | 69 while (!identical(next, this)) { |
73 E entry = next; | 70 E entry = next; |
74 next = entry._next; | 71 next = entry._next; |
75 entry._next = entry._previous = entry._list = null; | 72 entry._next = entry._previous = entry._list = null; |
76 } | 73 } |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 _list._insertAfter(this, entry); | 223 _list._insertAfter(this, entry); |
227 } | 224 } |
228 | 225 |
229 /** | 226 /** |
230 * Insert an element before this. | 227 * Insert an element before this. |
231 */ | 228 */ |
232 void insertBefore(E entry) { | 229 void insertBefore(E entry) { |
233 _list._insertAfter(_previous, entry); | 230 _list._insertAfter(_previous, entry); |
234 } | 231 } |
235 } | 232 } |
OLD | NEW |