MT Core (C++)
Core library for replacing C++ standard in project usage
|
Represents a ring buffer with dynamically allocated memory Can be used as a FIFO or LIFO queue Allows memory reuse rather than continuous memory allocations as it is used May be dynamically resized. More...
#include <ring_buffer.hpp>
Public Types | |
using | Elem = T |
Public Member Functions | |
decltype(auto) | ptr_iter () noexcept |
Gets iterator over pointers to elements. | |
decltype(auto) | ptr_iter () const noexcept |
Gets iterator over const pointers to elements. | |
decltype(auto) | iter () noexcept |
Gets iterator over values. | |
Result< void, AllocationError > | init (Allocator &alloc, size_t initCapacity=10) noexcept |
Initializes an empty ArrayList with an initial capacity. | |
Result< void, AllocationError > | init (Allocator &alloc, std::initializer_list< T > init, size_t capacity=0) noexcept |
Initializes an ring buffer with specified elements. | |
void | deinit (Allocator &alloc) |
Cleans up any memory held by ring buffer. | |
const T & | operator[] (size_t i) const noexcept |
Access element. | |
T & | operator[] (size_t i) noexcept |
Access element. | |
size_t | size () const noexcept |
Get size. | |
size_t | capacity () const noexcept |
Get capacity. | |
const T & | at (size_t i) const noexcept |
Access element. | |
T & | at (size_t i) noexcept |
Access element. | |
Result< void, AllocationError > | push_back (Allocator &alloc, const T &elem) |
Add element to back of buffer. | |
Result< void, AllocationError > | push_front (Allocator &alloc, const T &elem) |
Add element to front of buffer. | |
Result< void, CollectionAddNoAllocationError > | push_back (const T &elem) |
Add element to back of buffer. | |
Result< void, AllocationError > | shrink_to_fit (Allocator &alloc) |
Result< void, CollectionAddNoAllocationError > | push_front (const T &elem) |
Add element to front of buffer. | |
Optional< T > | pop_front () |
Removes and returns element from front. | |
Optional< T > | pop_back () |
Removes and returns element from back. | |
Represents a ring buffer with dynamically allocated memory Can be used as a FIFO or LIFO queue Allows memory reuse rather than continuous memory allocations as it is used May be dynamically resized.
Accessing elements is \(O(1)\) Adding elements is worst case \(O(N)\), but generally is \(O(1)\) Removing elements is \(O(1)\)
T | Type of element stored |
Definition at line 42 of file ring_buffer.hpp.
using mtcore::RingBuffer< T >::Elem = T |
Definition at line 50 of file ring_buffer.hpp.
|
inlinenodiscardnoexcept |
Access element.
Definition at line 156 of file ring_buffer.hpp.
|
inlinenoexcept |
|
inlinenodiscardnoexcept |
Get capacity.
Definition at line 153 of file ring_buffer.hpp.
|
inline |
Cleans up any memory held by ring buffer.
alloc | Allocator to use for cleanup |
Definition at line 128 of file ring_buffer.hpp.
|
inlinenoexcept |
Initializes an empty ArrayList with an initial capacity.
alloc | Allocator to use for initial allocation |
initCapacity | (Optional) Initial capacity to have (defaults to 10) |
Definition at line 83 of file ring_buffer.hpp.
|
inlinenoexcept |
Initializes an ring buffer with specified elements.
alloc | Allocator to use for initial allocation |
init | Initial value list |
capacity | (Optional) initial capacity (if bigger than the initial value list) |
Definition at line 104 of file ring_buffer.hpp.
|
inlinenoexcept |
Gets iterator over values.
Definition at line 72 of file ring_buffer.hpp.
|
inlinenoexcept |
Access element.
Definition at line 140 of file ring_buffer.hpp.
|
inlinenoexcept |
Access element.
Definition at line 145 of file ring_buffer.hpp.
|
inline |
Removes and returns element from back.
Returns nullopt if empty
Definition at line 284 of file ring_buffer.hpp.
|
inline |
Removes and returns element from front.
Returns nullopt if empty
Definition at line 267 of file ring_buffer.hpp.
|
inlinenoexcept |
Gets iterator over const pointers to elements.
Definition at line 64 of file ring_buffer.hpp.
|
inlinenoexcept |
Gets iterator over pointers to elements.
Definition at line 56 of file ring_buffer.hpp.
|
inline |
Add element to back of buffer.
Allocate more memory if needed
Definition at line 178 of file ring_buffer.hpp.
|
inline |
Add element to back of buffer.
Errors if full
Definition at line 204 of file ring_buffer.hpp.
|
inline |
Add element to front of buffer.
Allocate more memory if needed
Definition at line 191 of file ring_buffer.hpp.
|
inline |
Add element to front of buffer.
Errors if full
Definition at line 246 of file ring_buffer.hpp.
|
inline |
Definition at line 219 of file ring_buffer.hpp.
|
inlinenodiscardnoexcept |
Get size.
Definition at line 151 of file ring_buffer.hpp.