MT Core (C++)
Core library for replacing C++ standard in project usage
|
Array list is a growable, dynamic array with elements inside Elements are stored in an array, and are copied when resizing needs to happen Accessing elements is \(O(1)\) Adding elements is worst case \(O(N)\) Removing elements while preserving order is \(O(N)\) Removing elements while not preserving order is \(O(1)\). More...
#include <array_list.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 () const 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 array list with specified elements. | |
void | deinit (Allocator &alloc) noexcept |
Cleans up any memory held by array list. | |
Result< void, AllocationError > | push (Allocator &alloc, const Slice< std::add_const_t< T > > &elems) noexcept |
Pushes a list of items onto an array list. | |
Result< void, AllocationError > | push (Allocator &alloc, const Slice< std::remove_const_t< T > > &elems) noexcept |
Pushes a list of items onto an array list. | |
Result< void, AllocationError > | push (Allocator &alloc, const T &elem) noexcept |
Pushes an item onto an array list. | |
size_t | size () const noexcept |
Gets the size of an array list. | |
size_t | capacity () const noexcept |
Array list capacity. | |
Result< void, AllocationError > | reserve (Allocator &alloc, const size_t newSize) noexcept |
Will grow the capacity to be at least newSize large. | |
Result< void, AllocationError > | shrink_to_fit (Allocator &alloc) noexcept |
Will shrink the capacity to match the current size. | |
Result< void, CollectionAddNoAllocationError > | push (const Slice< std::remove_const_t< T > > &elems) noexcept |
Pushes an item onto the end of the ArrayList Will fail if there is not enough room. | |
Result< void, CollectionAddNoAllocationError > | push (const Slice< std::add_const_t< T > > &elems) noexcept |
Pushes an item onto the end of the ArrayList Will fail if there is not enough room. | |
Result< void, CollectionAddNoAllocationError > | push (const T &elem) noexcept |
Pushes an item onto the end of the ArrayList Will fail if there is not enough room. | |
Result< void, AllocationError > | unshift (const T &elem) noexcept |
Adds an element to the front, and shifts all other elements down by 1 If there is not enough room, will Result in a failure. | |
Result< void, AllocationError > | unshift (Allocator &alloc, const T &elem) noexcept |
Adds an element to the front, and shifts all other elements down by 1 If there is not enough room, will try to allocate more room. | |
Optional< T > | shift () noexcept |
Removes the first element and shifts all remaining elements down. | |
Optional< T > | pop () noexcept |
Pops the last element and returns it Will return an error if there is no element. | |
T & | at (size_t index) noexcept |
Get element at an index. | |
const T & | at (size_t index) const noexcept |
Get element at an index. | |
T & | operator[] (size_t index) noexcept |
Get element at an index. | |
const T & | operator[] (size_t index) const noexcept |
Get element at an index. | |
T | swap_remove (size_t index) noexcept |
Removes the element at an index (must be present) Does NOT preserve ordering Will swap the removed element with the last element and then pop Completes in \(O(1)\). | |
T | shift_remove (size_t index) noexcept |
Removes the element at an index (must be present) Does preserve ordering Will shift all remaining elements over by one Completes in \(O(N)\). | |
Slice< T > | slice () |
Gets a slice over the underlying elements. | |
Slice< std::add_const_t< T > > | slice () const |
Gets a slice over the underlying elements. | |
Array list is a growable, dynamic array with elements inside Elements are stored in an array, and are copied when resizing needs to happen Accessing elements is \(O(1)\) Adding elements is worst case \(O(N)\) Removing elements while preserving order is \(O(N)\) Removing elements while not preserving order is \(O(1)\).
T | Elements to store |
Definition at line 46 of file array_list.hpp.
using mtcore::ArrayList< T >::Elem = T |
Definition at line 52 of file array_list.hpp.
|
inlinenodiscardnoexcept |
Get element at an index.
index | Element index to get |
Definition at line 391 of file array_list.hpp.
|
inlinenodiscardnoexcept |
Get element at an index.
index | Element index to get |
Definition at line 381 of file array_list.hpp.
|
inlinenodiscardnoexcept |
Array list capacity.
Definition at line 199 of file array_list.hpp.
|
inlinenoexcept |
Cleans up any memory held by array list.
alloc | Allocator to use for cleanup |
Definition at line 122 of file array_list.hpp.
|
inlinenodiscardnoexcept |
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 76 of file array_list.hpp.
|
inlinenodiscardnoexcept |
Initializes an array list 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 96 of file array_list.hpp.
|
inlinenodiscardnoexcept |
Gets iterator over values.
Definition at line 68 of file array_list.hpp.
|
inlinenoexcept |
Get element at an index.
index | Element index to get |
Definition at line 411 of file array_list.hpp.
|
inlinenoexcept |
Get element at an index.
index | Element index to get |
Definition at line 401 of file array_list.hpp.
|
inlinenoexcept |
Pops the last element and returns it Will return an error if there is no element.
Definition at line 367 of file array_list.hpp.
|
inlinenodiscardnoexcept |
Gets iterator over const pointers to elements.
Definition at line 63 of file array_list.hpp.
|
inlinenodiscardnoexcept |
Gets iterator over pointers to elements.
Definition at line 58 of file array_list.hpp.
|
inlinenodiscardnoexcept |
Pushes a list of items onto an array list.
If there is no more room, will allocate a new list and do a copy If allocation fails, will return a failure
alloc | Allocator to use for potential allocations |
elems | Elements to add |
Definition at line 138 of file array_list.hpp.
|
inlinenodiscardnoexcept |
Pushes a list of items onto an array list.
If there is no more room, will allocate a new list and do a copy If allocation fails, will return a failure
alloc | Allocator to use for potential allocations |
elems | Elements to add |
Definition at line 160 of file array_list.hpp.
|
inlinenodiscardnoexcept |
Pushes an item onto an array list.
If there is no more room, will allocate a new list and do a copy If allocation fails, will return a failure
alloc | Allocator to use for potential allocations |
elem | Element to add |
Definition at line 173 of file array_list.hpp.
|
inlinenodiscardnoexcept |
Pushes an item onto the end of the ArrayList Will fail if there is not enough room.
elems | Element to add |
Definition at line 276 of file array_list.hpp.
|
inlinenodiscardnoexcept |
Pushes an item onto the end of the ArrayList Will fail if there is not enough room.
elems | Element to add |
Definition at line 266 of file array_list.hpp.
|
inlinenodiscardnoexcept |
Pushes an item onto the end of the ArrayList Will fail if there is not enough room.
elem | Element to add |
Definition at line 295 of file array_list.hpp.
|
inlinenodiscardnoexcept |
Will grow the capacity to be at least newSize large.
alloc | Allocator to use to resize |
newSize | New minimum capacity size |
Definition at line 210 of file array_list.hpp.
|
inlinenoexcept |
Removes the first element and shifts all remaining elements down.
Definition at line 354 of file array_list.hpp.
|
inlinenoexcept |
Removes the element at an index (must be present) Does preserve ordering Will shift all remaining elements over by one Completes in \(O(N)\).
index | Index of element to remove. Must be a valid index |
Definition at line 445 of file array_list.hpp.
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
Gets the size of an array list.
Definition at line 190 of file array_list.hpp.
|
inlinenodiscard |
Gets a slice over the underlying elements.
Definition at line 460 of file array_list.hpp.
|
inlinenodiscard |
Gets a slice over the underlying elements.
Definition at line 465 of file array_list.hpp.
|
inlinenoexcept |
Removes the element at an index (must be present) Does NOT preserve ordering Will swap the removed element with the last element and then pop Completes in \(O(1)\).
index | Index of element to remove. Must be a valid index |
Definition at line 424 of file array_list.hpp.
|
inlinenodiscardnoexcept |
Adds an element to the front, and shifts all other elements down by 1 If there is not enough room, will try to allocate more room.
alloc | Allocator to use to grow (if needed) |
elem | Element to add |
Definition at line 334 of file array_list.hpp.
|
inlinenodiscardnoexcept |
Adds an element to the front, and shifts all other elements down by 1 If there is not enough room, will Result in a failure.
elem | Element to add |
Definition at line 311 of file array_list.hpp.