Add BufferedIterator, an iterator with look-ahead/peek support.

Review Request #12639 — Created Sept. 24, 2022 and submitted

Information

RBTools
release-4.x

Reviewers

BufferedIterator wraps an existing iterable and allows the consumer to
peek contents without consuming the iterable. It's particularly useful
for parsing output from commands or diff generation, and to allow more
efficient chained processing.

This is implemented as an iterator wrapping another iterator, with a
deque used to hold the buffer. When peeking, we ensure the buffer has
been populated with the number of items to peek and we return from
there. When consuming or iterating, we start by retrieving items from
the buffer before retrieving from the iterator.

Unit tests pass.

Used this with some in-progress work for chained diff processing.

Summary ID
Add BufferedIterator, an iterator with look-ahead/peek support.
`BufferedIterator` wraps an existing iterable and allows the consumer to peek contents without consuming the iterable. It's particularly useful for parsing output from commands or diff generation, and to allow more efficient chained processing. This is implemented as an iterator wrapping another iterator, with a `deque` used to hold the buffer. When peeking, we ensure the buffer has been populated with the number of items to peek and we return from there. When consuming or iterating, we start by retrieving items from the buffer before retrieving from the iterator.
b0031a043a1395cc0b9c569e2f6e24109256fd48
david
  1. Ship It!
  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-4.x (7b4b3f9)
Loading...