| 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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 while (!identical(entry, _sentinel)) { | 290 while (!identical(entry, _sentinel)) { |
| 291 DoubleLinkedQueueEntry<E> nextEntry = entry._next; | 291 DoubleLinkedQueueEntry<E> nextEntry = entry._next; |
| 292 f(entry); | 292 f(entry); |
| 293 entry = nextEntry; | 293 entry = nextEntry; |
| 294 } | 294 } |
| 295 } | 295 } |
| 296 | 296 |
| 297 _DoubleLinkedQueueIterator<E> get iterator { | 297 _DoubleLinkedQueueIterator<E> get iterator { |
| 298 return new _DoubleLinkedQueueIterator<E>(_sentinel); | 298 return new _DoubleLinkedQueueIterator<E>(_sentinel); |
| 299 } | 299 } |
| 300 | |
| 301 // TODO(zarah) Remove this, and let it be inherited by IterableBase | |
| 302 String toString() => IterableMixinWorkaround.toStringIterable(this, '{', '}'); | |
| 303 } | 300 } |
| 304 | 301 |
| 305 class _DoubleLinkedQueueIterator<E> implements Iterator<E> { | 302 class _DoubleLinkedQueueIterator<E> implements Iterator<E> { |
| 306 _DoubleLinkedQueueEntrySentinel<E> _sentinel; | 303 _DoubleLinkedQueueEntrySentinel<E> _sentinel; |
| 307 DoubleLinkedQueueEntry<E> _currentEntry = null; | 304 DoubleLinkedQueueEntry<E> _currentEntry = null; |
| 308 E _current; | 305 E _current; |
| 309 | 306 |
| 310 _DoubleLinkedQueueIterator(_DoubleLinkedQueueEntrySentinel<E> sentinel) | 307 _DoubleLinkedQueueIterator(_DoubleLinkedQueueEntrySentinel<E> sentinel) |
| 311 : _sentinel = sentinel, _currentEntry = sentinel; | 308 : _sentinel = sentinel, _currentEntry = sentinel; |
| 312 | 309 |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 void clear() { | 516 void clear() { |
| 520 if (_head != _tail) { | 517 if (_head != _tail) { |
| 521 for (int i = _head; i != _tail; i = (i + 1) & (_table.length - 1)) { | 518 for (int i = _head; i != _tail; i = (i + 1) & (_table.length - 1)) { |
| 522 _table[i] = null; | 519 _table[i] = null; |
| 523 } | 520 } |
| 524 _head = _tail = 0; | 521 _head = _tail = 0; |
| 525 _modificationCount++; | 522 _modificationCount++; |
| 526 } | 523 } |
| 527 } | 524 } |
| 528 | 525 |
| 529 // TODO(zarah) Remove this, and let it be inherited by IterableBase | |
| 530 String toString() => IterableMixinWorkaround.toStringIterable(this, '{', '}'); | |
| 531 | |
| 532 // Queue interface. | 526 // Queue interface. |
| 533 | 527 |
| 534 void addLast(E element) { _add(element); } | 528 void addLast(E element) { _add(element); } |
| 535 | 529 |
| 536 void addFirst(E element) { | 530 void addFirst(E element) { |
| 537 _head = (_head - 1) & (_table.length - 1); | 531 _head = (_head - 1) & (_table.length - 1); |
| 538 _table[_head] = element; | 532 _table[_head] = element; |
| 539 if (_head == _tail) _grow(); | 533 if (_head == _tail) _grow(); |
| 540 _modificationCount++; | 534 _modificationCount++; |
| 541 } | 535 } |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 _queue._checkModification(_modificationCount); | 690 _queue._checkModification(_modificationCount); |
| 697 if (_position == _end) { | 691 if (_position == _end) { |
| 698 _current = null; | 692 _current = null; |
| 699 return false; | 693 return false; |
| 700 } | 694 } |
| 701 _current = _queue._table[_position]; | 695 _current = _queue._table[_position]; |
| 702 _position = (_position + 1) & (_queue._table.length - 1); | 696 _position = (_position + 1) & (_queue._table.length - 1); |
| 703 return true; | 697 return true; |
| 704 } | 698 } |
| 705 } | 699 } |
| OLD | NEW |