libboxes
boxes is a set of specialised containers built on top of STL
|
Implements a vector-like container that uses a linked list of fixed-size chunks to store its elements. More...
#include <linked_vector.hpp>
Public Member Functions | |
LinkedVector () | |
Constructs an empty container. More... | |
LinkedVector (LinkedVector< T, ChunkSizeV > &&other) | |
Move constructor. More... | |
LinkedVector< T, ChunkSizeV > & | operator= (LinkedVector< T, ChunkSizeV > &&other) |
Move assignment operator. More... | |
void | swap (LinkedVector< T, ChunkSizeV > &other) |
Swaps the contents of this LinkedVector with another. More... | |
template<typename Arg > | |
void | push_front (Arg &&value) |
Pushes a new element to the front of the container. More... | |
template<typename Arg > | |
void | push_back (Arg &&value) |
Pushes a new element to the back of the container. More... | |
void | pop_front () |
Removes the first element from the container. More... | |
void | pop_back () |
Removes the last element from the container. More... | |
T & | front () |
Returns a reference to the first element in the container. More... | |
const T & | front () const |
Returns a const reference to the first element in the container. More... | |
T & | back () |
Returns a reference to the last element in the container. More... | |
const T & | back () const |
Returns a const reference to the last element in the container. More... | |
T & | operator[] (size_type pos) |
Provides access to the element at the specified position. More... | |
const T & | operator[] (size_type pos) const |
Returns a const reference to the element at the specified position. More... | |
T & | at (size_type pos) |
Returns a reference to the element at the specified position. More... | |
const T & | at (size_type pos) const |
Returns a const reference to the element at the specified position. More... | |
iterator | begin () |
Returns an iterator to the first element of the container. More... | |
iterator | end () |
Returns an iterator to the element following the last element of the container. More... | |
iterator | cbegin () const |
Returns a const iterator to the first element of the container. More... | |
iterator | cend () const |
Returns a const iterator to the element following the last element. More... | |
bool | operator== (const LinkedVector< T, ChunkSizeV > &other) const |
Returns true if the two containers are equal. More... | |
bool | operator!= (const LinkedVector< T, ChunkSizeV > &other) const |
Returns true if the two containers are not equal. More... | |
std::size_t | size () const BOXES_NOTHROW |
Returns the number of elements in the container. More... | |
std::size_t | capacity () const BOXES_NOTHROW |
Returns the maximum number of elements the container can hold without additional memory allocation. More... | |
void | clear () |
Removes all elements from the container. More... | |
bool | empty () const BOXES_NOTHROW |
Returns true if the container is empty. More... | |
Implements a vector-like container that uses a linked list of fixed-size chunks to store its elements.
The LinkedVector class is a container that provides a similar interface to std::vector, but uses a linked list of fixed-size chunks to store its elements. This allows for efficient insertion and deletion at both ends of the container, as well as efficient memory usage for large containers.
Internally, the LinkedVector uses RingBuffer objects as chunks to store its elements.
To minimise the number of memory allocations, the LinkedVector maintains a list of discarded chunks that can be reused when new chunks are needed. When a chunk is no longer needed, it is moved to the list of discarded chunks rather than being deallocated.
T | The type of the elements stored in the container. |
ChunkSizeV | The size of the chunks used to store the elements. |
Definition at line 44 of file linked_vector.hpp.
|
inline |
Constructs an empty container.
Definition at line 112 of file linked_vector.hpp.
|
inline |
Move constructor.
other | The LinkedVector to move from |
Definition at line 121 of file linked_vector.hpp.
|
inline |
Returns a reference to the element at the specified position.
If pos is not within the range of the container, an exception of type std::out_of_range is thrown.
pos | The position of the element to access |
Definition at line 324 of file linked_vector.hpp.
|
inline |
Returns a const reference to the element at the specified position.
If pos is not within the range of the container, an exception of type std::out_of_range is thrown.
pos | The position of the element to access |
Definition at line 340 of file linked_vector.hpp.
|
inline |
Returns a reference to the last element in the container.
If the container is empty, an exception of type std::out_of_range is thrown.
Definition at line 264 of file linked_vector.hpp.
|
inline |
Returns a const reference to the last element in the container.
Definition at line 277 of file linked_vector.hpp.
|
inline |
Returns an iterator to the first element of the container.
Definition at line 349 of file linked_vector.hpp.
|
inline |
Returns the maximum number of elements the container can hold without additional memory allocation.
The capacity of a LinkedVector is the maximum number of elements it can hold without additional memory allocation. This is the number of elements that can be stored in the currently allocated chunks.
Definition at line 444 of file linked_vector.hpp.
|
inline |
Returns a const iterator to the first element of the container.
Definition at line 365 of file linked_vector.hpp.
|
inline |
Returns a const iterator to the element following the last element.
Definition at line 373 of file linked_vector.hpp.
|
inline |
Removes all elements from the container.
Definition at line 451 of file linked_vector.hpp.
|
inline |
Returns true if the container is empty.
Definition at line 462 of file linked_vector.hpp.
|
inline |
Returns an iterator to the element following the last element of the container.
Definition at line 358 of file linked_vector.hpp.
|
inline |
Returns a reference to the first element in the container.
If the container is empty, an exception of type std::out_of_range is thrown.
Definition at line 238 of file linked_vector.hpp.
|
inline |
Returns a const reference to the first element in the container.
If the container is empty, an exception of type std::out_of_range is thrown.
Definition at line 254 of file linked_vector.hpp.
|
inline |
Returns true if the two containers are not equal.
other | The container to compare with |
Definition at line 405 of file linked_vector.hpp.
|
inline |
Move assignment operator.
other | The LinkedVector to move from |
Definition at line 138 of file linked_vector.hpp.
|
inline |
Returns true if the two containers are equal.
The two containers are considered equal if they have the same number of elements and all the elements, compared in order, are equal.
other | The container to compare with |
Definition at line 384 of file linked_vector.hpp.
|
inline |
Provides access to the element at the specified position.
No bounds checking is performed.
pos | The position of the element to access |
Definition at line 287 of file linked_vector.hpp.
|
inline |
Returns a const reference to the element at the specified position.
No bounds checking is performed.
pos | The position of the element to access |
Definition at line 311 of file linked_vector.hpp.
|
inline |
Removes the last element from the container.
The time complexity of this operation is O(1).
If the back chunk becomes empty after the removal, it is moved to the pool of discarded chunks. No deallocation is performed.
Definition at line 221 of file linked_vector.hpp.
|
inline |
Removes the first element from the container.
The time complexity of this operation is O(1).
If the front chunk becomes empty after the removal, it is moved to the pool of discarded chunks. No deallocation is performed.
Definition at line 204 of file linked_vector.hpp.
|
inline |
Pushes a new element to the back of the container.
Newly inserted element is retrievable with back
method.
The time complexity of this operation is O(1).
May incur a chunk allocation if the back chunk is full and the pool of discarded chunks is empty.
Arg | The type of the argument to push |
value | The value to push to the back of the container |
Definition at line 191 of file linked_vector.hpp.
|
inline |
Pushes a new element to the front of the container.
Newly inserted element is retrievable with front
method.
The time complexity of this operation is O(1).
May incur a chunk allocation if the front chunk is full and the pool of discarded chunks is empty.
Arg | The type of the argument to push |
value | The value to push to the front of the container |
Definition at line 173 of file linked_vector.hpp.
|
inline |
Returns the number of elements in the container.
Definition at line 414 of file linked_vector.hpp.
|
inline |
Swaps the contents of this LinkedVector with another.
other | The LinkedVector to swap with |
Definition at line 153 of file linked_vector.hpp.