geomc 1.0
A c++ linear algebra template library
|
A lightweight circular buffer. More...
#include <geomc/CircularBuffer.h>
Public Member Functions | |
CircularBuffer () | |
Construct a new empty circular buffer, with capacity for N items. | |
CircularBuffer (index_t capacity) | |
Construct a new empty circular buffer, with space for at least capacity items. | |
template<typename InputIterator > | |
CircularBuffer (InputIterator begin, index_t count) | |
Construct a new circular buffer by copying count items in the sequence starting at begin . | |
CircularBuffer (const CircularBuffer< T, N > &other) | |
Construct a new circular buffer containing copies of all the items in other . | |
CircularBuffer (CircularBuffer< T, N > &&other) | |
Move the contents of other to a new CircularBuffer. | |
CircularBuffer & | operator= (const CircularBuffer &other) |
Assignment operator. | |
CircularBuffer & | operator= (CircularBuffer &&other) |
Move the contents of other to this buffer. | |
T & | operator[] (index_t i) |
Get the i th element in the buffer. More... | |
const T & | operator[] (index_t i) const |
Get the i th (const) element in the buffer. More... | |
bool | operator== (const CircularBuffer< T, N > &other) |
Equality operator. More... | |
bool | operator!= (const CircularBuffer< T, N > &other) |
Inequality operator. | |
index_t | size () const |
Return the number of items in the buffer. | |
index_t | capacity () const |
Return the total number of items that can be accommodated without an additional memory allocation. | |
template<typename U > | |
void | push_back (U &&t) |
Add an element to the end of the buffer. | |
template<typename U > | |
void | push_front (U &&t) |
Add an element to the beginning of the buffer. More... | |
T | pop_front () |
Remove the first element in the buffer. More... | |
T | pop_back () |
Remove the element at the end of the buffer. | |
T & | front () |
Return a reference to the item at the beginning of the buffer. | |
const T & | front () const |
Return a const reference to the item at the beginning of the buffer. | |
T & | back () |
Return a reference to the item at the end of the buffer. | |
const T & | back () const |
Return a const reference to the item at the end of the buffer. | |
void | clear () |
Empty the buffer of all items. | |
void | reserve (index_t new_cap) |
Increase the capacity of the circular buffer to a value that's greater or equal to new_cap . If new_cap is greater than the current capacity, then new storage is allocated; otherwise the method does nothing. | |
Protected Member Functions | |
T * | get () |
const T * | get () const |
T * | item (index_t i) |
const T * | item (index_t i) const |
A lightweight circular buffer.
A circular buffer can accommodate adding elements to either the front or the back of the list in constant time.
Furthermore, indexing off the end of the circular buffer wraps around to the beginning again. This works in both directions.
T | Element type. |
N | Static capacity of the buffer. Adding more than this number of elements to the buffer will incur a heap memory allocation. To always use heap allocation, pass zero to this parameter, in which case memory will be allocated when the first element is added. |
|
inline |
Equality operator.
Two CircularBuffers are equal iff they contain equal elements in equal order.
|
inline |
Get the i
th element in the buffer.
Indicies beyond the end of the buffer will wrap around again to the beginning. Negative indices are permitted and count from the end of the buffer, with -1 denoting the last element in the buffer.
|
inline |
Get the i
th (const) element in the buffer.
Indicies beyond the end of the buffer will wrap around again to the beginning. Negative indices are permitted and count from the end of the buffer, with -1 denoting the last element in the buffer.
|
inline |
Remove the first element in the buffer.
This decreases the indices of all the remaining elements by one.
|
inline |
Add an element to the beginning of the buffer.
This increases the indices of all the existing elements by one. The new element will have index zero.