Chromium Code Reviews| Index: pkg/analysis_server/lib/src/collections.dart |
| diff --git a/pkg/analysis_server/lib/src/collections.dart b/pkg/analysis_server/lib/src/collections.dart |
| index e89350e41d622f650f9965780142c4a6a078c616..6f4109590d23c0e1b79744ad61b865ea17a337a6 100644 |
| --- a/pkg/analysis_server/lib/src/collections.dart |
| +++ b/pkg/analysis_server/lib/src/collections.dart |
| @@ -45,3 +45,27 @@ class Pair<E, F> { |
| String toString() => '($first, $last)'; |
| } |
| + |
| +/** |
| + * A container that remembers the last `n` items added to it. |
| + * |
| + * It will never grow larger than `capacity`. It's a LIFO queue - the last item |
|
scheglov
2017/06/02 16:43:22
[capacity]
devoncarew
2017/06/02 16:51:02
Done.
|
| + * added will be the first one returned from [items]. |
| + */ |
| +class RecentBuffer<T> { |
| + final int capacity; |
| + |
| + List<T> _buffer = []; |
| + |
| + RecentBuffer(this.capacity); |
| + |
| + void add(T item) { |
| + _buffer.add(item); |
| + |
| + if (_buffer.length > capacity) { |
| + _buffer.removeAt(0); |
| + } |
| + } |
| + |
| + Iterable<T> get items => _buffer.reversed; |
| +} |