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

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

chipx86
RBTools
release-4.x
rbtools

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
Add BufferedIterator, an iterator with look-ahead/peek support.
david
  1. Ship It!
  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Change Summary:

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