| 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 dart.collection; | 5 part of dart.collection; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * A [Queue] is a collection that can be manipulated at both ends. One | 8 * A [Queue] is a collection that can be manipulated at both ends. One |
| 9 * can iterate over the elements of a queue through [forEach] or with | 9 * can iterate over the elements of a queue through [forEach] or with |
| 10 * an [Iterator]. | 10 * an [Iterator]. |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 DoubleLinkedQueueEntry<E> nextEntry = entry._next; | 294 DoubleLinkedQueueEntry<E> nextEntry = entry._next; |
| 295 f(entry); | 295 f(entry); |
| 296 entry = nextEntry; | 296 entry = nextEntry; |
| 297 } | 297 } |
| 298 } | 298 } |
| 299 | 299 |
| 300 _DoubleLinkedQueueIterator<E> get iterator { | 300 _DoubleLinkedQueueIterator<E> get iterator { |
| 301 return new _DoubleLinkedQueueIterator<E>(_sentinel); | 301 return new _DoubleLinkedQueueIterator<E>(_sentinel); |
| 302 } | 302 } |
| 303 | 303 |
| 304 String toString() { | 304 // TODO(zarah) Remove this, and let it be inherited by IterableBase |
| 305 return ToString.iterableToString(this); | 305 String toString() => IterableMixinWorkaround.toStringIterable(this, '{', '}'); |
| 306 } | |
| 307 } | 306 } |
| 308 | 307 |
| 309 class _DoubleLinkedQueueIterator<E> implements Iterator<E> { | 308 class _DoubleLinkedQueueIterator<E> implements Iterator<E> { |
| 310 _DoubleLinkedQueueEntrySentinel<E> _sentinel; | 309 _DoubleLinkedQueueEntrySentinel<E> _sentinel; |
| 311 DoubleLinkedQueueEntry<E> _currentEntry = null; | 310 DoubleLinkedQueueEntry<E> _currentEntry = null; |
| 312 E _current; | 311 E _current; |
| 313 | 312 |
| 314 _DoubleLinkedQueueIterator(_DoubleLinkedQueueEntrySentinel<E> sentinel) | 313 _DoubleLinkedQueueIterator(_DoubleLinkedQueueEntrySentinel<E> sentinel) |
| 315 : _sentinel = sentinel, _currentEntry = sentinel; | 314 : _sentinel = sentinel, _currentEntry = sentinel; |
| 316 | 315 |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 void clear() { | 522 void clear() { |
| 524 if (_head != _tail) { | 523 if (_head != _tail) { |
| 525 for (int i = _head; i != _tail; i = (i + 1) & (_table.length - 1)) { | 524 for (int i = _head; i != _tail; i = (i + 1) & (_table.length - 1)) { |
| 526 _table[i] = null; | 525 _table[i] = null; |
| 527 } | 526 } |
| 528 _head = _tail = 0; | 527 _head = _tail = 0; |
| 529 _modificationCount++; | 528 _modificationCount++; |
| 530 } | 529 } |
| 531 } | 530 } |
| 532 | 531 |
| 533 String toString() { | 532 // TODO(zarah) Remove this, and let it be inherited by IterableBase |
| 534 return ToString.iterableToString(this); | 533 String toString() => IterableMixinWorkaround.toStringIterable(this, '{', '}'); |
| 535 } | |
| 536 | 534 |
| 537 // Queue interface. | 535 // Queue interface. |
| 538 | 536 |
| 539 void addLast(E element) { _add(element); } | 537 void addLast(E element) { _add(element); } |
| 540 | 538 |
| 541 void addFirst(E element) { | 539 void addFirst(E element) { |
| 542 _head = (_head - 1) & (_table.length - 1); | 540 _head = (_head - 1) & (_table.length - 1); |
| 543 _table[_head] = element; | 541 _table[_head] = element; |
| 544 if (_head == _tail) _grow(); | 542 if (_head == _tail) _grow(); |
| 545 _modificationCount++; | 543 _modificationCount++; |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 _queue._checkModification(_modificationCount); | 699 _queue._checkModification(_modificationCount); |
| 702 if (_position == _end) { | 700 if (_position == _end) { |
| 703 _current = null; | 701 _current = null; |
| 704 return false; | 702 return false; |
| 705 } | 703 } |
| 706 _current = _queue._table[_position]; | 704 _current = _queue._table[_position]; |
| 707 _position = (_position + 1) & (_queue._table.length - 1); | 705 _position = (_position + 1) & (_queue._table.length - 1); |
| 708 return true; | 706 return true; |
| 709 } | 707 } |
| 710 } | 708 } |
| OLD | NEW |