15 while ((element<<1) < max)
19 if (j+1 < max && array[j] < array[j+1])
22 if (array[element] < array[j])
25 array[j] = array[element];
43 T* virtualArray = array - 1;
44 int virtualSize = size + 2;
49 for (i=((size-1)/2); i>=0; --i)
50 heapsink(virtualArray, i+1, virtualSize-1);
54 for (i=size-1; i>=0; --i)
73 : data(0), used(0), allocated(0),
74 free_when_destroyed(
true), is_sorted(
true)
81 : data(0), used(0), allocated(0),
82 free_when_destroyed(true), is_sorted(true)
101 if (free_when_destroyed)
113 data =
new T[new_size];
114 allocated = new_size;
116 int end = used < new_size ? used : new_size;
117 for (
int i=0; i<end; ++i)
118 data[i] = old_data[i];
120 if (allocated < used)
133 if (used + 1 > allocated)
136 data[used++] = element;
173 free_when_destroyed = f;
182 if (allocated < usedNow)
197 if (other.allocated == 0)
200 data =
new T[other.allocated];
203 free_when_destroyed = other.free_when_destroyed;
204 is_sorted = other.is_sorted;
205 allocated = other.allocated;
207 for (DWORD i=0; i<other.used; ++i)
208 data[i] = other.data[i];
309 if (is_sorted || used<2)
352 if (element < data[m])
357 }
while((element < data[m] || data[m] < element) && left<=right);
364 if (!(element < data[m]) && !(data[m] < element))
378 for (DWORD i=0; i<used; ++i)
379 if (!(element < data[i]) && !(data[i] < element))
393 for (
int i=used-1; i>=0; --i)
394 if (data[i] == element)
408 if (index>=used || index<0)
412 for (DWORD i=index+1; i<used; ++i)
426 if (index>=used || index<0 || count<1 || index+count>used)
430 for (DWORD i=index+count; i<used; ++i)
431 data[i-count] = data[i];
440 is_sorted = _is_sorted;
449 bool free_when_destroyed;
const T * const_pointer() const
Returns a const pointer to the array.
Definition: Array.h:270
const T & getLast() const
Gets last frame.
Definition: Array.h:237
void sort()
Sorts the array using heapsort.
Definition: Array.h:307
void clear()
Clears the array and deletes all allocated memory.
Definition: Array.h:143
void reallocate(DWORD new_size)
Reallocates the array, make it bigger or smaller.
Definition: Array.h:109
void set_pointer(T *newPointer, DWORD size)
Sets pointer to new array, using this as new workspace.
Definition: Array.h:157
void heapsink(T *array, int element, int max)
Sinks an element into the heap.
Definition: Array.h:13
T * pointer()
Returns a pointer to the array.
Definition: Array.h:261
DWORD size() const
Returns size of used array.
Definition: Array.h:279
void set_sorted(bool _is_sorted)
Sets if the array is sorted.
Definition: Array.h:438
different physics engine has different winding order.
Definition: EventBinding.h:32
void push_back(const T &element)
Adds an element at back of array.
Definition: Array.h:131
int linear_reverse_search(T &element)
Finds an element in linear time, which is very slow.
Definition: Array.h:391
DWORD allocated_size() const
Returns amount memory allocated.
Definition: Array.h:289
int linear_search(T &element)
Finds an element in linear time, which is very slow.
Definition: Array.h:376
void erase(DWORD index, int count)
Erases some elements from the array.
Definition: Array.h:423
T & getLast()
Gets last frame.
Definition: Array.h:248
bool empty() const
Returns true if array is empty.
Definition: Array.h:298
array(const array< T > &other)
Copy constructor.
Definition: Array.h:89
T & operator[](DWORD index)
Direct access operator.
Definition: Array.h:213
void erase(DWORD index)
Erases an element from the array.
Definition: Array.h:405
~array()
Destructor.
Definition: Array.h:99
void heapsort(T *array, int size)
Sorts an array with size 'size' using heapsort.
Definition: Array.h:37
Self reallocating template array (like stl vector) with additional features.
Definition: Array.h:67
void set_free_when_destroyed(bool f)
Sets if the array should delete the memory it used.
Definition: Array.h:171
void operator=(const array< T > &other)
Assignment operator.
Definition: Array.h:191
array(DWORD start_count)
Constructs a array and allocates an initial chunk of memory.
Definition: Array.h:80
int binary_search(const T &element)
Performs a binary search for an element, returns -1 if not found.
Definition: Array.h:324
void set_used(DWORD usedNow)
Sets the size of the array.
Definition: Array.h:180
int binary_search(const T &element, int left, int right)
Performs a binary search for an element, returns -1 if not found.
Definition: Array.h:339