![]() |
Skylicht Engine
|
Self reallocating template array (like stl vector) with additional features. More...
#include <C:/Projects/skylicht-engine/Projects/Irrlicht/Include/irrArray.h>
Public Member Functions | |
| array () | |
| Default constructor for empty array. | |
| array (u32 start_count) | |
| Constructs an array and allocates an initial chunk of memory. | |
| array (const array< T, TAlloc > &other) | |
| Copy constructor. | |
| ~array () | |
| Destructor. | |
| void | reallocate (u32 new_size, bool canShrink=true) |
| Reallocates the array, make it bigger or smaller. | |
| void | setAllocStrategy (eAllocStrategy newStrategy=ALLOC_STRATEGY_DOUBLE) |
| set a new allocation strategy | |
| void | push_back (const T &element) |
| Adds an element at back of array. | |
| void | push_front (const T &element) |
| Adds an element at the front of the array. | |
| void | insert (const T &element, u32 index=0) |
| Insert item into array at specified position. | |
| void | clear () |
| Clears the array and deletes all allocated memory. | |
| void | set_pointer (T *newPointer, u32 size, bool _is_sorted=false, bool _free_when_destroyed=true) |
| Sets pointer to new array, using this as new workspace. | |
| void | set_free_when_destroyed (bool f) |
| Sets if the array should delete the memory it uses upon destruction. | |
| void | set_used (u32 usedNow) |
| Sets the size of the array and allocates new elements if necessary. | |
| const array< T, TAlloc > & | operator= (const array< T, TAlloc > &other) |
| Assignment operator. | |
| bool | operator== (const array< T, TAlloc > &other) const |
| Equality operator. | |
| bool | operator!= (const array< T, TAlloc > &other) const |
| Inequality operator. | |
| T & | operator[] (u32 index) |
| Direct access operator. | |
| const T & | operator[] (u32 index) const |
| Direct const access operator. | |
| T & | getLast () |
| Gets last element. | |
| const T & | getLast () const |
| Gets last element. | |
| T * | pointer () |
| Gets a pointer to the array. | |
| const T * | const_pointer () const |
| Gets a const pointer to the array. | |
| u32 | size () const |
| Get number of occupied elements of the array. | |
| u32 | allocated_size () const |
| Get amount of memory allocated. | |
| bool | empty () const |
| Check if array is empty. | |
| void | sort () |
| Sorts the array using heapsort. | |
| s32 | binary_search (const T &element) |
| Performs a binary search for an element, returns -1 if not found. | |
| s32 | binary_search (const T &element) const |
| Performs a binary search for an element if possible, returns -1 if not found. | |
| s32 | binary_search (const T &element, s32 left, s32 right) const |
| Performs a binary search for an element, returns -1 if not found. | |
| s32 | binary_search_multi (const T &element, s32 &last) |
| s32 | linear_search (const T &element) const |
| Finds an element in linear time, which is very slow. | |
| s32 | linear_reverse_search (const T &element) const |
| Finds an element in linear time, which is very slow. | |
| void | erase (u32 index) |
| Erases an element from the array. | |
| void | erase (u32 index, s32 count) |
| Erases some elements from the array. | |
| void | set_sorted (bool _is_sorted) |
| Sets if the array is sorted. | |
| void | swap (array< T, TAlloc > &other) |
| Swap the content of this array container with the content of another array. | |
Self reallocating template array (like stl vector) with additional features.
Some features are: Heap sorting, binary search methods, easier debugging.
|
inline |
Constructs an array and allocates an initial chunk of memory.
| start_count | Amount of elements to pre-allocate. |
|
inline |
Destructor.
Frees allocated memory, if set_free_when_destroyed was not set to false by the user before.
|
inline |
Get amount of memory allocated.
|
inline |
Performs a binary search for an element, returns -1 if not found.
The array will be sorted before the binary search if it is not already sorted. Caution is advised! Be careful not to call this on unsorted const arrays, or the slower method will be used.
| element | Element to search for. |
|
inline |
Performs a binary search for an element if possible, returns -1 if not found.
This method is for const arrays and so cannot call sort(), if the array is not sorted then linear_search will be used instead. Potentially very slow!
| element | Element to search for. |
|
inline |
Performs a binary search for an element, returns -1 if not found.
| element | Element to search for. |
| left | First left index |
| right | Last right index. |
|
inline |
Performs a binary search for an element, returns -1 if not found. it is used for searching a multiset The array will be sorted before the binary search if it is not already sorted.
| element | Element to search for. |
| &last | return lastIndex of equal elements |
|
inline |
Gets a const pointer to the array.
|
inline |
Check if array is empty.
|
inline |
Erases an element from the array.
May be slow, because all elements following after the erased element have to be copied.
| index | Index of element to be erased. |
|
inline |
Erases some elements from the array.
May be slow, because all elements following after the erased element have to be copied.
| index | Index of the first element to be erased. |
| count | Amount of elements to be erased. |
|
inline |
Insert item into array at specified position.
Please use this only if you know what you are doing (possible performance loss). The preferred method of adding elements should be push_back().
| element | Element to be inserted |
| index | Where position to insert the new element. |
|
inline |
Finds an element in linear time, which is very slow.
Use binary_search for faster finding. Only works if ==operator is implemented.
| element | Element to search for. |
|
inline |
Finds an element in linear time, which is very slow.
Use binary_search for faster finding. Only works if ==operator is implemented.
| element | Element to search for. |
|
inline |
Gets a pointer to the array.
|
inline |
Adds an element at back of array.
If the array is too small to add this new element it is made bigger.
| element | Element to add at the back of the array. |
|
inline |
Adds an element at the front of the array.
If the array is to small to add this new element, the array is made bigger. Please note that this is slow, because the whole array needs to be copied for this.
| element | Element to add at the back of the array. |
|
inline |
Reallocates the array, make it bigger or smaller.
| new_size | New size of array. |
| canShrink | Specifies whether the array is reallocated even if enough space is available. Setting this flag to false can speed up array usage, but may use more memory than required by the data. |
|
inline |
Sets if the array should delete the memory it uses upon destruction.
Also clear and set_pointer will only delete the (original) memory area if this flag is set to true, which is also the default. The methods reallocate, set_used, push_back, push_front, insert, and erase will still try to deallocate the original memory, which might cause troubles depending on the intended use of the memory area.
| f | If true, the array frees the allocated memory in its destructor, otherwise not. The default is true. |
|
inline |
Sets pointer to new array, using this as new workspace.
Make sure that set_free_when_destroyed is used properly.
| newPointer | Pointer to new array of elements. |
| size | Size of the new array. |
| _is_sorted | Flag which tells whether the new array is already sorted. |
| _free_when_destroyed | Sets whether the new memory area shall be freed by the array upon destruction, or if this will be up to the user application. |
|
inline |
Sets the size of the array and allocates new elements if necessary.
Please note: This is only secure when using it with simple types, because no default constructor will be called for the added elements.
| usedNow | Amount of elements now used. |
|
inline |
set a new allocation strategy
if the maximum size of the array is unknown, you can define how big the allocation should happen.
| newStrategy | New strategy to apply to this array. |
|
inline |
Get number of occupied elements of the array.
|
inline |
Sorts the array using heapsort.
There is no additional memory waste and the algorithm performs O(n*log n) in worst case.
|
inline |
Swap the content of this array container with the content of another array.
Afterwards this object will contain the content of the other object and the other object will contain the content of this object.
| other | Swap content with this object |