Graphitti
A toolkit/software architecture to ease creating high-performance neural network simulators
|
Public Member Functions | |
CircularBuffer (int capacity=0) | |
Create a circular buffer with the given capacity. | |
void | resize (int capacity) |
Resize the circular buffer. | |
void | put (T element) |
Inserts the given element at the front of the queue. | |
std::optional< T > | get () |
Retrieves the element at the end of the queue. | |
std::optional< T > | peek () const |
Retrieves the element at the end of the buffer withouth dequeueing it. | |
void | clear () |
Clears the circular buffer. | |
bool | isEmpty () const |
Returns true if the buffer is empty, false otherwise. | |
bool | isFull () const |
Returns true if the buffer is full, false otherwise. | |
size_t | capacity () const |
Retrieves the number of elements that this buffer can hold. | |
size_t | size () const |
Retrieves the number of elements currently stored in the buffer. | |
Definition at line 28 of file CircularBuffer.h.
|
inline |
Create a circular buffer with the given capacity.
Create and size the buffer so it can hold a set number of elements. If the size is set on instantiation, the buffer should not be resize. The size of the underlying data structure is set to capacity+1, to distinguish between a full and empty buffer.
capacity | The number of elements that the buffer can hold, defaults to zero |
Definition at line 38 of file CircularBuffer.h.
|
inline |
Retrieves the number of elements that this buffer can hold.
Note that the underlying vector is sized one over the buffer capacity to distinguish between a full and empty buffer.
Definition at line 134 of file CircularBuffer.h.
|
inline |
Clears the circular buffer.
Definition at line 103 of file CircularBuffer.h.
|
inline |
Retrieves the element at the end of the queue.
The method returns the element wrapped in an std::optional data type. If the buffer is empty we return an empty std::optional constructed from std::nullopt.
Definition at line 75 of file CircularBuffer.h.
|
inline |
Returns true
if the buffer is empty, false
otherwise.
true
if the buffer is empty, false
otherwise Definition at line 111 of file CircularBuffer.h.
|
inline |
Returns true
if the buffer is full, false
otherwise.
We distinguish between an empty and full buffer by always having an unused space between the front and the end of the queue. A full buffer has the front one space behind the end of the queue.
true
if the buffer is full, false
otherwise Definition at line 123 of file CircularBuffer.h.
|
inline |
Retrieves the element at the end of the buffer withouth dequeueing it.
Definition at line 93 of file CircularBuffer.h.
|
inline |
Inserts the given element at the front of the queue.
element | The element to be inserted into the queue |
Definition at line 58 of file CircularBuffer.h.
|
inline |
Resize the circular buffer.
capacity | The number of elements that the buffer can hold |
Definition at line 46 of file CircularBuffer.h.
|
inline |
Retrieves the number of elements currently stored in the buffer.
Definition at line 141 of file CircularBuffer.h.