| 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 Link<T> link = this; |
| 73 for (int i = 0 ; i < n ; i++) { |
| 74 if (link.isEmpty) { |
| 75 throw new RangeError('Index $n out of range'); |
| 76 } |
| 77 link = link.tail; |
| 78 } |
| 79 return link; |
| 80 } |
| 71 | 81 |
| 72 bool get isEmpty => false; | 82 bool get isEmpty => false; |
| 73 | 83 |
| 74 List<T> toList() { | 84 List<T> toList() { |
| 75 List<T> list = new List<T>(); | 85 List<T> list = new List<T>(); |
| 76 for (Link<T> link = this; !link.isEmpty; link = link.tail) { | 86 for (Link<T> link = this; !link.isEmpty; link = link.tail) { |
| 77 list.addLast(link.head); | 87 list.addLast(link.head); |
| 78 } | 88 } |
| 79 return list; | 89 return list; |
| 80 } | 90 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 if (head == null) { | 131 if (head == null) { |
| 122 head = entry; | 132 head = entry; |
| 123 } else { | 133 } else { |
| 124 lastLink.tail = entry; | 134 lastLink.tail = entry; |
| 125 } | 135 } |
| 126 lastLink = entry; | 136 lastLink = entry; |
| 127 } | 137 } |
| 128 | 138 |
| 129 bool get isEmpty => length == 0; | 139 bool get isEmpty => length == 0; |
| 130 } | 140 } |
| OLD | NEW |