Chromium Code Reviews| 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 | 5 |
| 6 /** | 6 /** |
| 7 * An entry in a doubly linked list. It contains a pointer to the next | 7 * An entry in a doubly linked list. It contains a pointer to the next |
| 8 * entry, the previous entry, and the boxed element. | 8 * entry, the previous entry, and the boxed element. |
| 9 */ | 9 */ |
| 10 class DoubleLinkedQueueEntry<E> { | 10 class DoubleLinkedQueueEntry<E> { |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 bool some(bool f(E element)) { | 198 bool some(bool f(E element)) { |
| 199 DoubleLinkedQueueEntry<E> entry = _sentinel._next; | 199 DoubleLinkedQueueEntry<E> entry = _sentinel._next; |
| 200 while (entry !== _sentinel) { | 200 while (entry !== _sentinel) { |
| 201 DoubleLinkedQueueEntry<E> nextEntry = entry._next; | 201 DoubleLinkedQueueEntry<E> nextEntry = entry._next; |
| 202 if (f(entry._element)) return true; | 202 if (f(entry._element)) return true; |
| 203 entry = nextEntry; | 203 entry = nextEntry; |
| 204 } | 204 } |
| 205 return false; | 205 return false; |
| 206 } | 206 } |
| 207 | 207 |
| 208 Queue map(f(E element)) { | |
| 209 Queue<E> other = new Queue(); | |
|
ahe
2012/01/05 22:36:54
Remove <E>.
| |
| 210 DoubleLinkedQueueEntry<E> entry = _sentinel._next; | |
| 211 while (entry !== _sentinel) { | |
| 212 DoubleLinkedQueueEntry<E> nextEntry = entry._next; | |
| 213 other.addLast(f(entry._element)); | |
| 214 entry = nextEntry; | |
| 215 } | |
| 216 return other; | |
| 217 } | |
| 218 | |
| 219 | |
| 208 Queue<E> filter(bool f(E element)) { | 220 Queue<E> filter(bool f(E element)) { |
| 209 Queue<E> other = new Queue<E>(); | 221 Queue<E> other = new Queue<E>(); |
| 210 DoubleLinkedQueueEntry<E> entry = _sentinel._next; | 222 DoubleLinkedQueueEntry<E> entry = _sentinel._next; |
| 211 while (entry !== _sentinel) { | 223 while (entry !== _sentinel) { |
| 212 DoubleLinkedQueueEntry<E> nextEntry = entry._next; | 224 DoubleLinkedQueueEntry<E> nextEntry = entry._next; |
| 213 if (f(entry._element)) other.addLast(entry._element); | 225 if (f(entry._element)) other.addLast(entry._element); |
| 214 entry = nextEntry; | 226 entry = nextEntry; |
| 215 } | 227 } |
| 216 return other; | 228 return other; |
| 217 } | 229 } |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 234 } | 246 } |
| 235 | 247 |
| 236 E next() { | 248 E next() { |
| 237 if (!hasNext()) { | 249 if (!hasNext()) { |
| 238 throw const NoMoreElementsException(); | 250 throw const NoMoreElementsException(); |
| 239 } | 251 } |
| 240 _currentEntry = _currentEntry._next; | 252 _currentEntry = _currentEntry._next; |
| 241 return _currentEntry.element; | 253 return _currentEntry.element; |
| 242 } | 254 } |
| 243 } | 255 } |
| OLD | NEW |