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