OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 * Returns the concatenation of the input [iterables]. | 6 * Returns the concatenation of the input [iterables]. |
7 * | 7 * |
8 * The returned iterable is a lazily-evaluated view on the input iterables. | 8 * The returned iterable is a lazily-evaluated view on the input iterables. |
9 */ | 9 */ |
10 Iterable/*<E>*/ concat/*<E>*/(Iterable<Iterable/*<E>*/ > iterables) => | 10 Iterable/*<E>*/ concat/*<E>*/(Iterable<Iterable/*<E>*/ > iterables) => |
(...skipping 27 matching lines...) Expand all Loading... |
38 | 38 |
39 int get hashCode => first.hashCode ^ last.hashCode; | 39 int get hashCode => first.hashCode ^ last.hashCode; |
40 | 40 |
41 bool operator ==(other) { | 41 bool operator ==(other) { |
42 if (other is! Pair) return false; | 42 if (other is! Pair) return false; |
43 return other.first == first && other.last == last; | 43 return other.first == first && other.last == last; |
44 } | 44 } |
45 | 45 |
46 String toString() => '($first, $last)'; | 46 String toString() => '($first, $last)'; |
47 } | 47 } |
| 48 |
| 49 /** |
| 50 * A container that remembers the last `n` items added to it. |
| 51 * |
| 52 * It will never grow larger than [capacity]. It's a LIFO queue - the last item |
| 53 * added will be the first one returned from [items]. |
| 54 */ |
| 55 class RecentBuffer<T> { |
| 56 final int capacity; |
| 57 |
| 58 List<T> _buffer = []; |
| 59 |
| 60 RecentBuffer(this.capacity); |
| 61 |
| 62 void add(T item) { |
| 63 _buffer.add(item); |
| 64 |
| 65 if (_buffer.length > capacity) { |
| 66 _buffer.removeAt(0); |
| 67 } |
| 68 } |
| 69 |
| 70 Iterable<T> get items => _buffer.reversed; |
| 71 } |
OLD | NEW |