Ocean
|
Vector like data structure combining stack and heap memory. More...
Data Structures | |
class | ConstIterator |
Definition of an iterator allowing to iterate through the vector. More... | |
class | Iterator |
Definition of an iterator allowing to iterate through the vector. More... | |
Public Member Functions | |
StackHeapVector () | |
Creates a new vector object. More... | |
StackHeapVector (const size_t size, const T &element) | |
Creates a new vector object. More... | |
void | pushBack (T &&element) |
Pushes a new element to the end of this vector. More... | |
void | pushBack (const T &element) |
Pushes a new element to the end of this vector. More... | |
template<typename... TArgs> | |
T & | emplaceBack (TArgs &&... args) |
Emplaces a new element to the end of this vector. More... | |
void | popBack () |
Removed the last elements from the vector. More... | |
void | resize (const size_t size) |
Resizes the vector. More... | |
void | assign (const size_t size, const T &element) |
Replaces the content of the vector with 'size' copies of the provided element. More... | |
size_t | size () const |
Returns the number of elements of this vector. More... | |
size_t | capacity () const |
Returns the overall capacity of this vector (including the capacity on the stack and on the heap). More... | |
bool | isEmpty () const |
Returns whether this vector is empty. More... | |
void | clear () |
Clears this vector. More... | |
void | setCapacity (const size_t capacity) |
Sets the capacity of this vector to a specified number of elements. More... | |
const T & | front () const |
Returns the first element of this vector. More... | |
T & | front () |
Returns the first element of this vector. More... | |
const T & | back () const |
Returns the last element of this vector. More... | |
T & | back () |
Returns the last element of this vector. More... | |
Iterator | begin () |
Returns an iterator to the first element in this vector. More... | |
Iterator | end () |
Returns an iterator to the element following the last element in this vector. More... | |
ConstIterator | begin () const |
Returns a const iterator to the first element in this vector. More... | |
ConstIterator | end () const |
Returns an iterator to the element following the last element in this vector. More... | |
const T & | operator[] (const size_t index) const |
Elements access operator. More... | |
T & | operator[] (const size_t index) |
Elements access operator. More... | |
Protected Attributes | |
T | stackElements_ [tStackCapacity] |
The elements located on the stack. More... | |
std::vector< T > | heapElements_ |
The remaining elements located on the heap. More... | |
size_t | size_ = 0 |
The number of elements in this vector. More... | |
Vector like data structure combining stack and heap memory.
This class implements a vector-like data structure which stores the first tStackCapacity
elements on the stack, and any additional elements on the heap.
This approach can optimize performance and memory usage when the number of elements is often within the tStackCapacity
but can occasionally exceed it.
T | Data type of the elements that will be stored |
tStackCapacity | Number of elements that can be stored on the stack, with range [1, infinity) |
Ocean::StackHeapVector< T, tStackCapacity >::StackHeapVector |
Creates a new vector object.
Ocean::StackHeapVector< T, tStackCapacity >::StackHeapVector | ( | const size_t | size, |
const T & | element | ||
) |
Creates a new vector object.
size | The number of elements to be created |
element | The value that will be created in the first 'number' elements of this vector |
void Ocean::StackHeapVector< T, tStackCapacity >::assign | ( | const size_t | size, |
const T & | element | ||
) |
Replaces the content of the vector with 'size' copies of the provided element.
size | The new size of the vector, with range [0, infinity) |
element | The element which will be copied into all places of the resized vector |
T & Ocean::StackHeapVector< T, tStackCapacity >::back |
Returns the last element of this vector.
Ensure that the vector is not empty before calling this function.
const T & Ocean::StackHeapVector< T, tStackCapacity >::back |
Returns the last element of this vector.
Ensure that the vector is not empty before calling this function.
StackHeapVector< T, tStackCapacity >::Iterator Ocean::StackHeapVector< T, tStackCapacity >::begin |
Returns an iterator to the first element in this vector.
StackHeapVector< T, tStackCapacity >::ConstIterator Ocean::StackHeapVector< T, tStackCapacity >::begin |
Returns a const iterator to the first element in this vector.
|
inline |
Returns the overall capacity of this vector (including the capacity on the stack and on the heap).
void Ocean::StackHeapVector< T, tStackCapacity >::clear |
Clears this vector.
All stack elements will be overwritten with default values.
T & Ocean::StackHeapVector< T, tStackCapacity >::emplaceBack | ( | TArgs &&... | args | ) |
Emplaces a new element to the end of this vector.
args | The arguments of the new element |
TArgs | The data types of the arguments |
StackHeapVector< T, tStackCapacity >::Iterator Ocean::StackHeapVector< T, tStackCapacity >::end |
Returns an iterator to the element following the last element in this vector.
StackHeapVector< T, tStackCapacity >::ConstIterator Ocean::StackHeapVector< T, tStackCapacity >::end |
Returns an iterator to the element following the last element in this vector.
T & Ocean::StackHeapVector< T, tStackCapacity >::front |
Returns the first element of this vector.
Ensure that the vector is not empty before calling this function.
const T & Ocean::StackHeapVector< T, tStackCapacity >::front |
Returns the first element of this vector.
Ensure that the vector is not empty before calling this function.
|
inline |
Returns whether this vector is empty.
|
inline |
Elements access operator.
index | The index of the element to access, with range [0, size() - 1] |
|
inline |
Elements access operator.
index | The index of the element to access, with range [0, size() - 1] |
void Ocean::StackHeapVector< T, tStackCapacity >::popBack |
Removed the last elements from the vector.
The vector must not be empty.
void Ocean::StackHeapVector< T, tStackCapacity >::pushBack | ( | const T & | element | ) |
Pushes a new element to the end of this vector.
element | The new element to be pushed |
void Ocean::StackHeapVector< T, tStackCapacity >::pushBack | ( | T && | element | ) |
Pushes a new element to the end of this vector.
element | The new element to be pushed |
void Ocean::StackHeapVector< T, tStackCapacity >::resize | ( | const size_t | size | ) |
Resizes the vector.
size | The new size of the vector |
void Ocean::StackHeapVector< T, tStackCapacity >::setCapacity | ( | const size_t | capacity | ) |
Sets the capacity of this vector to a specified number of elements.
In case the specified capacity is smaller than the current capacity or is smaller than the number of elements in this vector, nothing happens.
capacity | The capacity to set, with range [0, infinity) |
|
inline |
Returns the number of elements of this vector.
|
protected |
The remaining elements located on the heap.
|
protected |
The number of elements in this vector.
|
protected |
The elements located on the stack.