An optimized circular buffer. More...
#include <CircularBuffer.h>
Public Types | |
typedef std::vector< T >::iterator | iterator |
typedef std::vector< T >::const_iterator | const_iterator |
Public Member Functions | |
CircularBuffer () | |
CircularBuffer (const std::size_t capacity) | |
virtual void | erase (const std::size_t num) override |
Remove the first num elements. More... | |
virtual void | eraseChunk (const std::size_t chunk_size) override |
virtual Buffer< T >::iterator | beginChunk (const std::size_t chunk_size) override |
Iterator for the first entry with a given chunk size in the buffer If chunk_size is greater than the size of the buffer, the full range will be given. More... | |
virtual Buffer< T >::const_iterator | beginChunk (const std::size_t chunk_size) const override |
Const iterator for the first entry with a given chunk size in the buffer If chunk_size is greater than the size of the buffer, the full range will be given. More... | |
virtual Buffer< T >::iterator | endChunk (const std::size_t chunk_size) override |
Iterator for the last entry of a chunk size in the buffer If chunk_size is greater than the size of the buffer, the full range will be given. More... | |
virtual Buffer< T >::const_iterator | endChunk (const std::size_t chunk_size) const override |
Const iterator for the last entry of a chunk size in the buffer If chunk_size is greater than the size of the buffer, the full range will be given. More... | |
void | setCapacity (const std::size_t capacity) |
Resize the capacity. More... | |
std::size_t | capacity () const |
Get the capacity. More... | |
void | setSize (const std::size_t size) |
Set the size. More... | |
std::size_t | size () const |
Get the size. More... | |
bool | empty () const |
Whether or not the buffer is empty. More... | |
void | push_back (const T &value) |
Add a new entry on the end. More... | |
void | move (T &value) |
Moves the object into the buffer (calls std::move()) More... | |
void | append (const_iterator in_begin, const_iterator in_end) |
Add new entries to the end. More... | |
void | append (const std::vector< T > &vals) |
Add new entries to the end. More... | |
void | clear () |
Remove all entries (does not change the capacity) Note: this does NOT at all free any entries. More... | |
iterator | begin () |
Iterator for the first entry in the buffer. More... | |
const_iterator | begin () const |
Const iterator for the first entry in the buffer. More... | |
iterator | end () |
Iterator for the last entry in the buffer. More... | |
const_iterator | end () const |
Const iterator for the last entry in the buffer. More... | |
T & | operator[] (const std::size_t index) |
Access an entry at index. More... | |
const T & | operator[] (const std::size_t index) const |
Const access an entry at an index. More... | |
void | swap (std::vector< T > &in_data) |
Use in_data as our data vector. More... | |
const std::vector< T > & | data () |
Access the raw underlying storage. More... | |
std::size_t | dataBeginPos () const |
The current beginning position of the buffer in data(). More... | |
std::size_t | dataEndPos () const |
The current end position of the buffer in data(). More... | |
Protected Member Functions | |
virtual std::size_t | newEnd (const std::size_t new_end) override |
Find out where the new end will be. More... | |
Protected Attributes | |
std::vector< T > | _data |
The raw data. More... | |
std::size_t | _begin_pos |
The beginning position. More... | |
std::size_t | _end_pos |
The ending position. More... | |
An optimized circular buffer.
This also always ensures that begin() < end(). That means that if the end of the buffer capacity is reached, an O(N) operation will be used to move data from the end of the capacity to the beginning
This is done so that begin()/end() iterators can be used in OpenMP loops Also means that operator[] works sequentially between 0 and size()
It will also automatically grow larger if capacity is reached
NOTE: This buffer will not properly wrap around as a standard circular buffer does. Once the end of the internal storage has been reached, the data will be moved to the beginning of the internal storage via a copy. This is needed to ensure that the access through the begin()/end() iterators is contiguous.
Definition at line 36 of file CircularBuffer.h.
|
inherited |
|
inherited |
MooseUtils::CircularBuffer< T >::CircularBuffer | ( | ) |
Definition at line 57 of file CircularBuffer.h.
MooseUtils::CircularBuffer< T >::CircularBuffer | ( | const std::size_t | capacity | ) |
Definition at line 62 of file CircularBuffer.h.
|
inherited |
Add new entries to the end.
Everything in [in_begin, in_end) is appended
Definition at line 241 of file Buffer.h.
|
inherited |
Add new entries to the end.
Definition at line 253 of file Buffer.h.
|
inlineinherited |
Iterator for the first entry in the buffer.
Definition at line 113 of file Buffer.h.
|
inlineinherited |
Const iterator for the first entry in the buffer.
Definition at line 117 of file Buffer.h.
|
overridevirtual |
Iterator for the first entry with a given chunk size in the buffer If chunk_size is greater than the size of the buffer, the full range will be given.
Implements MooseUtils::Buffer< T >.
Definition at line 91 of file CircularBuffer.h.
|
overridevirtual |
Const iterator for the first entry with a given chunk size in the buffer If chunk_size is greater than the size of the buffer, the full range will be given.
Implements MooseUtils::Buffer< T >.
Definition at line 98 of file CircularBuffer.h.
|
inlineinherited |
|
inherited |
Remove all entries (does not change the capacity) Note: this does NOT at all free any entries.
Definition at line 260 of file Buffer.h.
|
inlineinherited |
Access the raw underlying storage.
This is considered an advanced interface. Typically, you should use the begin(), beginChunk(), end(), and endChunk() methods for accessing the data. This should really only be used in unit tests for verifying the underlying storage.
Definition at line 172 of file Buffer.h.
|
inlineinherited |
The current beginning position of the buffer in data().
This is considered an advanced interface because data() is the internal storage for the buffer. It should really only be used in unit tests for verifying the underlying storage.
Definition at line 182 of file Buffer.h.
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
overridevirtual |
Iterator for the last entry of a chunk size in the buffer If chunk_size is greater than the size of the buffer, the full range will be given.
Implements MooseUtils::Buffer< T >.
Definition at line 105 of file CircularBuffer.h.
|
overridevirtual |
Const iterator for the last entry of a chunk size in the buffer If chunk_size is greater than the size of the buffer, the full range will be given.
Implements MooseUtils::Buffer< T >.
Definition at line 115 of file CircularBuffer.h.
|
overridevirtual |
Remove the first num elements.
Note that erased items are not guaranteed to be freed immediately
Implements MooseUtils::Buffer< T >.
Definition at line 68 of file CircularBuffer.h.
|
overridevirtual |
Implements MooseUtils::Buffer< T >.
Definition at line 81 of file CircularBuffer.h.
|
inherited |
|
overrideprotectedvirtual |
Find out where the new end will be.
This will resize/copy data as necessary
new_end | the proposed new_end position |
Implements MooseUtils::Buffer< T >.
Definition at line 125 of file CircularBuffer.h.
|
inherited |
Access an entry at index.
Definition at line 268 of file Buffer.h.
|
inherited |
Const access an entry at an index.
Definition at line 276 of file Buffer.h.
|
inherited |
|
inlineinherited |
|
inlineinherited |
Set the size.
Definition at line 58 of file Buffer.h.
|
inlineinherited |
Get the size.
Definition at line 62 of file Buffer.h.
Referenced by MooseUtils::Buffer< T >::empty().
|
inherited |
Use in_data as our data vector.
Definition at line 284 of file Buffer.h.
|
protectedinherited |
The beginning position.
Definition at line 208 of file Buffer.h.
Referenced by MooseUtils::Buffer< T >::begin(), MooseUtils::Buffer< T >::dataBeginPos(), MooseUtils::Buffer< T >::setSize(), and MooseUtils::Buffer< T >::size().
|
protectedinherited |
The raw data.
Definition at line 205 of file Buffer.h.
Referenced by MooseUtils::Buffer< T >::begin(), MooseUtils::Buffer< T >::capacity(), MooseUtils::Buffer< T >::data(), MooseUtils::Buffer< T >::end(), and MooseUtils::Buffer< T >::setCapacity().
|
protectedinherited |
The ending position.
Definition at line 210 of file Buffer.h.
Referenced by MooseUtils::Buffer< T >::dataEndPos(), MooseUtils::Buffer< T >::end(), MooseUtils::Buffer< T >::setSize(), and MooseUtils::Buffer< T >::size().