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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 return _table[(_tail - 1) & (_table.length - 1)]; | 420 return _table[(_tail - 1) & (_table.length - 1)]; |
421 } | 421 } |
422 | 422 |
423 E get single { | 423 E get single { |
424 if (_head == _tail) throw IterableElementError.noElement(); | 424 if (_head == _tail) throw IterableElementError.noElement(); |
425 if (length > 1) throw IterableElementError.tooMany(); | 425 if (length > 1) throw IterableElementError.tooMany(); |
426 return _table[_head]; | 426 return _table[_head]; |
427 } | 427 } |
428 | 428 |
429 E elementAt(int index) { | 429 E elementAt(int index) { |
430 if (index < 0 || index >= length) { | 430 RangeError.checkValidIndex(index, this); |
431 throw new RangeError.index(index, this); | |
432 } | |
433 return _table[(_head + index) & (_table.length - 1)]; | 431 return _table[(_head + index) & (_table.length - 1)]; |
434 } | 432 } |
435 | 433 |
436 List<E> toList({ bool growable: true }) { | 434 List<E> toList({ bool growable: true }) { |
437 List<E> list; | 435 List<E> list; |
438 if (growable) { | 436 if (growable) { |
439 list = new List<E>()..length = length; | 437 list = new List<E>()..length = length; |
440 } else { | 438 } else { |
441 list = new List<E>(length); | 439 list = new List<E>(length); |
442 } | 440 } |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 _queue._checkModification(_modificationCount); | 712 _queue._checkModification(_modificationCount); |
715 if (_position == _end) { | 713 if (_position == _end) { |
716 _current = null; | 714 _current = null; |
717 return false; | 715 return false; |
718 } | 716 } |
719 _current = _queue._table[_position]; | 717 _current = _queue._table[_position]; |
720 _position = (_position + 1) & (_queue._table.length - 1); | 718 _position = (_position + 1) & (_queue._table.length - 1); |
721 return true; | 719 return true; |
722 } | 720 } |
723 } | 721 } |
OLD | NEW |