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 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 } | 61 } |
| 62 | 62 |
| 63 Link<T> reversePrependAll(Link<T> from) { | 63 Link<T> reversePrependAll(Link<T> from) { |
| 64 Link<T> result; | 64 Link<T> result; |
| 65 for (result = this; !from.isEmpty; from = from.tail) { | 65 for (result = this; !from.isEmpty; from = from.tail) { |
| 66 result = result.prepend(from.head); | 66 result = result.prepend(from.head); |
| 67 } | 67 } |
| 68 return result; | 68 return result; |
| 69 } | 69 } |
| 70 | 70 |
| 71 Link<T> skip(int n) { | |
| 72 if (n == 0) return this; | |
| 73 return tail.skip(n-1); | |
|
ahe
2013/01/09 13:35:46
How about a for loop?
Johnni Winther
2013/01/09 14:29:11
Done.
| |
| 74 } | |
| 71 | 75 |
| 72 bool get isEmpty => false; | 76 bool get isEmpty => false; |
| 73 | 77 |
| 74 List<T> toList() { | 78 List<T> toList() { |
| 75 List<T> list = new List<T>(); | 79 List<T> list = new List<T>(); |
| 76 for (Link<T> link = this; !link.isEmpty; link = link.tail) { | 80 for (Link<T> link = this; !link.isEmpty; link = link.tail) { |
| 77 list.addLast(link.head); | 81 list.addLast(link.head); |
| 78 } | 82 } |
| 79 return list; | 83 return list; |
| 80 } | 84 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 if (head == null) { | 125 if (head == null) { |
| 122 head = entry; | 126 head = entry; |
| 123 } else { | 127 } else { |
| 124 lastLink.tail = entry; | 128 lastLink.tail = entry; |
| 125 } | 129 } |
| 126 lastLink = entry; | 130 lastLink = entry; |
| 127 } | 131 } |
| 128 | 132 |
| 129 bool get isEmpty => length == 0; | 133 bool get isEmpty => length == 0; |
| 130 } | 134 } |
| OLD | NEW |