OLD | NEW |
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 util_implementation; | 5 part of util_implementation; |
6 | 6 |
7 class LinkIterator<T> implements Iterator<T> { | 7 class LinkIterator<T> implements Iterator<T> { |
8 T _current; | 8 T _current; |
9 Link<T> _link; | 9 Link<T> _link; |
10 | 10 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 if (link.isEmpty) { | 74 if (link.isEmpty) { |
75 throw new RangeError('Index $n out of range'); | 75 throw new RangeError('Index $n out of range'); |
76 } | 76 } |
77 link = link.tail; | 77 link = link.tail; |
78 } | 78 } |
79 return link; | 79 return link; |
80 } | 80 } |
81 | 81 |
82 bool get isEmpty => false; | 82 bool get isEmpty => false; |
83 | 83 |
84 List<T> toList() { | 84 List<T> toList({ bool growable: false }) { |
85 List<T> list = new List<T>(); | 85 return new List<T>.from(this, growable: growable); |
86 for (Link<T> link = this; !link.isEmpty; link = link.tail) { | |
87 list.addLast(link.head); | |
88 } | |
89 return list; | |
90 } | 86 } |
91 | 87 |
92 void forEach(void f(T element)) { | 88 void forEach(void f(T element)) { |
93 for (Link<T> link = this; !link.isEmpty; link = link.tail) { | 89 for (Link<T> link = this; !link.isEmpty; link = link.tail) { |
94 f(link.head); | 90 f(link.head); |
95 } | 91 } |
96 } | 92 } |
97 | 93 |
98 bool operator ==(other) { | 94 bool operator ==(other) { |
99 if (other is !Link<T>) return false; | 95 if (other is !Link<T>) return false; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 if (head == null) { | 129 if (head == null) { |
134 head = entry; | 130 head = entry; |
135 } else { | 131 } else { |
136 lastLink.tail = entry; | 132 lastLink.tail = entry; |
137 } | 133 } |
138 lastLink = entry; | 134 lastLink = entry; |
139 } | 135 } |
140 | 136 |
141 bool get isEmpty => length == 0; | 137 bool get isEmpty => length == 0; |
142 } | 138 } |
OLD | NEW |