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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 * Implementation of a double linked list that box list elements into | 95 * Implementation of a double linked list that box list elements into |
96 * DoubleLinkedQueueEntry objects. | 96 * DoubleLinkedQueueEntry objects. |
97 */ | 97 */ |
98 class DoubleLinkedQueue<E> implements Queue<E> { | 98 class DoubleLinkedQueue<E> implements Queue<E> { |
99 _DoubleLinkedQueueEntrySentinel<E> _sentinel; | 99 _DoubleLinkedQueueEntrySentinel<E> _sentinel; |
100 | 100 |
101 DoubleLinkedQueue() { | 101 DoubleLinkedQueue() { |
102 _sentinel = new _DoubleLinkedQueueEntrySentinel<E>(); | 102 _sentinel = new _DoubleLinkedQueueEntrySentinel<E>(); |
103 } | 103 } |
104 | 104 |
105 // See issue 417. Works in the vm, fails in dartc and frog. | 105 factory DoubleLinkedQueue.from(Iterable<E> other) { |
106 factory DoubleLinkedQueue.from(Iterable/*<E>*/ other) { | 106 Queue<E> list = new DoubleLinkedQueue(); |
107 Queue/*<E>*/ list = new DoubleLinkedQueue(); | |
108 for (final e in other) { | 107 for (final e in other) { |
109 list.addLast(e); | 108 list.addLast(e); |
110 } | 109 } |
111 return list; | 110 return list; |
112 } | 111 } |
113 | 112 |
114 void addLast(E value) { | 113 void addLast(E value) { |
115 _sentinel.prepend(value); | 114 _sentinel.prepend(value); |
116 } | 115 } |
117 | 116 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 } | 234 } |
236 | 235 |
237 E next() { | 236 E next() { |
238 if (!hasNext()) { | 237 if (!hasNext()) { |
239 throw const NoMoreElementsException(); | 238 throw const NoMoreElementsException(); |
240 } | 239 } |
241 _currentEntry = _currentEntry._next; | 240 _currentEntry = _currentEntry._next; |
242 return _currentEntry.element; | 241 return _currentEntry.element; |
243 } | 242 } |
244 } | 243 } |
OLD | NEW |