MT Core (C++)
Core library for replacing C++ standard in project usage
|
Segmented list where each segment contains multiple nodes Allows growing the list without having to invalidate all previous memory addresses. More...
#include <segmented_list.hpp>
Classes | |
struct | ConstIter |
Const reference for mutating elements Using custom iterator for speed. More... | |
struct | ConstPtrIter |
Pointer iterator for mutating elements Using custom iterator for speed. More... | |
struct | PtrIter |
Pointer iterator for mutating elements Using custom iterator for speed. More... | |
Public Types | |
using | Elem = T |
Public Member Functions | |
PtrIter | ptr_iter () noexcept |
Mutable iterator that gives element pointers. | |
ConstPtrIter | ptr_iter () const noexcept |
Const iterator that gives const element pointers. | |
ConstIter | iter () const noexcept |
Const iterator that gives element references. | |
size_t | size () const noexcept |
Gets the size of the list. | |
Result< void, AllocationError > | init (Allocator &alloc, size_t initCapacity) |
Initializes a segmented list. | |
Result< void, AllocationError > | init (Allocator &alloc, std::initializer_list< T > list) |
Initializes a segmented list. | |
void | deinit (Allocator &alloc) |
Cleans up memory tied to segmented list. | |
void | drop_unused_segments (Allocator &alloc) |
Lowers memory footprint by dropping unused segments. | |
Result< void, CollectionAddNoAllocationError > | push (const T &elem) noexcept |
Pushes a new element. | |
Result< void, AllocationError > | push (Allocator &alloc, const T &elem) noexcept |
Pushes a new element. | |
const T & | operator[] (size_t index) const noexcept |
Access element at index. | |
T & | operator[] (size_t index) noexcept |
Access element at index. | |
const T & | at (size_t index) const noexcept |
Access element at index. | |
T & | at (size_t index) noexcept |
Access element at index. | |
bool | operator== (const SegmentedList &other) |
bool | operator!= (const SegmentedList &other) |
void | pop () |
remove last element | |
size_t | capacity () const |
Segmented list where each segment contains multiple nodes Allows growing the list without having to invalidate all previous memory addresses.
Only allows removing elements at the end.
The only operations which invalidate existing memory addresses are pop(), swap_remove(), and deinit() Otherwise, memory addresses are guaranteed to remain stable
Accessing elements is \(O(log_{1.5}(N))\) Adding elements is \(O(1)\) Removing elements is \(O(1)\), but only removes last element
For a more flexible removal/insertion,
Definition at line 45 of file segmented_list.hpp.
using mtcore::SegmentedList< T >::Elem = T |
Definition at line 46 of file segmented_list.hpp.
|
inlinenodiscardnoexcept |
Access element at index.
index | index to access |
Definition at line 372 of file segmented_list.hpp.
|
inlinenodiscardnoexcept |
Access element at index.
index | index to access |
Definition at line 391 of file segmented_list.hpp.
|
inlinenodiscard |
Definition at line 439 of file segmented_list.hpp.
|
inline |
Cleans up memory tied to segmented list.
alloc | allocator to clean up memory with |
Definition at line 241 of file segmented_list.hpp.
|
inline |
Lowers memory footprint by dropping unused segments.
alloc | Allocator to drop segments with |
Definition at line 262 of file segmented_list.hpp.
|
inlinenodiscard |
Initializes a segmented list.
alloc | Allocator to use for initializing memory |
initCapacity | Initial list capacity |
Definition at line 190 of file segmented_list.hpp.
|
inlinenodiscard |
Initializes a segmented list.
alloc | Allocator to use for initializing memory |
list | List of elements to initialize with |
Definition at line 212 of file segmented_list.hpp.
|
inlinenodiscardnoexcept |
Const iterator that gives element references.
Definition at line 173 of file segmented_list.hpp.
|
inlinenodiscard |
other | List to compare to |
Definition at line 427 of file segmented_list.hpp.
|
inlinenodiscard |
other | List to compare to |
Definition at line 409 of file segmented_list.hpp.
|
inlinenodiscardnoexcept |
Access element at index.
index | index to access |
Definition at line 352 of file segmented_list.hpp.
|
inlinenodiscardnoexcept |
Access element at index.
index | index to access |
Definition at line 362 of file segmented_list.hpp.
|
inline |
remove last element
Definition at line 432 of file segmented_list.hpp.
|
inlinenodiscardnoexcept |
Const iterator that gives const element pointers.
Definition at line 164 of file segmented_list.hpp.
|
inlinenodiscardnoexcept |
Mutable iterator that gives element pointers.
Definition at line 155 of file segmented_list.hpp.
|
inlinenodiscardnoexcept |
Pushes a new element.
Will allocate if there is no space
alloc | Allocator to use for additional allocation |
elem | Element to add |
Definition at line 314 of file segmented_list.hpp.
|
inlinenodiscardnoexcept |
Pushes a new element.
Will error if there is no space
elem | Element to add |
Definition at line 295 of file segmented_list.hpp.
|
inlinenodiscardnoexcept |
Gets the size of the list.
Definition at line 182 of file segmented_list.hpp.