|
My Project
|
Self reallocating template array (like stl vector) with additional features. More...
#include <Array.h>
Public Member Functions | |
| array (DWORD start_count) | |
| Constructs a array and allocates an initial chunk of memory. More... | |
| array (const array< T > &other) | |
| Copy constructor. | |
| ~array () | |
| Destructor. More... | |
| void | reallocate (DWORD new_size) |
| Reallocates the array, make it bigger or smaller. More... | |
| void | push_back (const T &element) |
| Adds an element at back of array. More... | |
| void | clear () |
| Clears the array and deletes all allocated memory. | |
| void | set_pointer (T *newPointer, DWORD size) |
| Sets pointer to new array, using this as new workspace. More... | |
| void | set_free_when_destroyed (bool f) |
| Sets if the array should delete the memory it used. More... | |
| void | set_used (DWORD usedNow) |
| Sets the size of the array. More... | |
| void | operator= (const array< T > &other) |
| Assignment operator. | |
| T & | operator[] (DWORD index) |
| Direct access operator. | |
| const T & | operator[] (DWORD index) const |
| Direct access operator. | |
| const T & | getLast () const |
| Gets last frame. | |
| T & | getLast () |
| Gets last frame. | |
| T * | pointer () |
| Returns a pointer to the array. More... | |
| const T * | const_pointer () const |
| Returns a const pointer to the array. More... | |
| DWORD | size () const |
| Returns size of used array. More... | |
| DWORD | allocated_size () const |
| Returns amount memory allocated. More... | |
| bool | empty () const |
| Returns true if array is empty. More... | |
| void | sort () |
| Sorts the array using heapsort. More... | |
| int | binary_search (const T &element) |
| Performs a binary search for an element, returns -1 if not found. More... | |
| int | binary_search (const T &element, int left, int right) |
| Performs a binary search for an element, returns -1 if not found. More... | |
| int | linear_search (T &element) |
| Finds an element in linear time, which is very slow. More... | |
| int | linear_reverse_search (T &element) |
| Finds an element in linear time, which is very slow. More... | |
| void | erase (DWORD index) |
| Erases an element from the array. More... | |
| void | erase (DWORD index, int count) |
| Erases some elements from the array. More... | |
| void | set_sorted (bool _is_sorted) |
| Sets if the array is sorted. | |
Self reallocating template array (like stl vector) with additional features.
Some features are: Heap sorting, binary search methods, easier debugging.
|
inline |
Constructs a array and allocates an initial chunk of memory.
| start_count | Amount of elements to allocate. |
|
inline |
Destructor.
Frees allocated memory, if set_free_when_destroyed was not set to false by the user before.
|
inline |
Returns amount 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.
| element | Element to search for. |
|
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.
| element | Element to search for. |
| left | First left index |
| right | Last right index. |
|
inline |
Returns a const pointer to the array.
|
inline |
Returns true 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 |
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 |
Returns a pointer to the array.
|
inline |
Adds an element at back of array.
If the array is to small to add this new element, the array is made bigger.
| 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. |
|
inline |
Sets if the array should delete the memory it used.
| 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.
| newPointer | Pointer to new array of elements. |
| size | Size of the new array. |
|
inline |
Sets the size of the array.
| usedNow | Amount of elements now used. |
|
inline |
Returns size of used array.
|
inline |
Sorts the array using heapsort.
There is no additional memory waste and the algorithm performs (O) n log n in worst case.
1.8.12