16 #ifndef BT_OBJECT_ARRAY__ 17 #define BT_OBJECT_ARRAY__ 28 #define BT_USE_PLACEMENT_NEW 1 30 #define BT_ALLOW_ARRAY_COPY_OPERATOR // enabling this can accidently perform deep copies of data if you are not careful 35 #endif //BT_USE_MEMCPY 37 #ifdef BT_USE_PLACEMENT_NEW 39 #endif //BT_USE_PLACEMENT_NEW 42 #if __cplusplus > 199711L 45 #define BT_REGISTER register 62 #ifdef BT_ALLOW_ARRAY_COPY_OPERATOR 69 #else //BT_ALLOW_ARRAY_COPY_OPERATOR 72 #endif //BT_ALLOW_ARRAY_COPY_OPERATOR 82 for (i = start; i < end; ++i)
84 new (&dest[i]) T(
m_data[i]);
87 #endif //BT_USE_PLACEMENT_NEW 101 for (i = first; i < last; i++)
143 int otherSize = otherArray.
size();
203 if (newsize >
size())
214 if (newsize < curSize)
216 for (
int i = newsize; i < curSize; i++)
223 if (newsize > curSize)
227 #ifdef BT_USE_PLACEMENT_NEW 228 for (
int i = curSize; i < newsize; i++)
230 new (&
m_data[i]) T(fillData);
232 #endif //BT_USE_PLACEMENT_NEW 257 #ifdef BT_USE_PLACEMENT_NEW 258 new (&
m_data[sz]) T(fillValue);
272 #ifdef BT_USE_PLACEMENT_NEW 276 #endif //BT_USE_PLACEMENT_NEW 317 template <
typename L>
323 T x =
m_data[(lo + hi) / 2];
328 while (CompareFunc(
m_data[i], x))
330 while (CompareFunc(x,
m_data[j]))
347 template <
typename L>
358 template <
typename L>
359 void downHeap(T* pArr,
int k,
int n,
const L& CompareFunc)
364 T temp = pArr[k - 1];
370 if ((child < n) && CompareFunc(pArr[child - 1], pArr[child]))
375 if (CompareFunc(temp, pArr[child - 1]))
378 pArr[k - 1] = pArr[child - 1];
389 void swap(
int index0,
int index1)
392 char temp[
sizeof(T)];
393 memcpy(temp, &
m_data[index0],
sizeof(T));
395 memcpy(&
m_data[index1], temp,
sizeof(T));
400 #endif //BT_USE_PLACEMENT_NEW 403 template <
typename L>
409 for (k = n / 2; k > 0; k--)
429 int last =
size() - 1;
432 while (first <= last)
434 int mid = (first + last) / 2;
437 else if (key <
m_data[mid])
450 for (i = 0; i <
size(); i++)
468 for (i = 0; i <
size(); i++)
487 void remove(
const T& key)
505 int otherSize = otherArray.
size();
511 #endif //BT_OBJECT_ARRAY__
void push_back(const T &_Val)
void deallocate(pointer ptr)
int findLinearSearch2(const T &key) const
void copy(int start, int end, T *dest) const
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
bool operator()(const T &a, const T &b) const
int findLinearSearch(const T &key) const
void * allocate(int size)
const T & operator[](int n) const
void resizeNoInitialize(int newsize)
resize changes the number of elements in the array.
void destroy(int first, int last)
const T & at(int n) const
#define SIMD_FORCE_INLINE
void copyFromArray(const btAlignedObjectArray &otherArray)
void downHeap(T *pArr, int k, int n, const L &CompareFunc)
heap sort from http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Sort/Heap/
void swap(int index0, int index1)
void heapSort(const L &CompareFunc)
void clear()
clear the array, deallocated memory. Generally it is better to use array.resize(0), to reduce performance overhead of run-time memory (de)allocations.
void removeAtIndex(int index)
#define BT_USE_PLACEMENT_NEW
If the platform doesn't support placement new, you can disable BT_USE_PLACEMENT_NEW then the btAligne...
int capacity() const
return the pre-allocated (reserved) elements, this is at least as large as the total number of elemen...
void initializeFromBuffer(void *buffer, int size, int capacity)
int size() const
return the number of elements in the array
btAlignedAllocator< T, 16 > m_allocator
btAlignedObjectArray(const btAlignedObjectArray &otherArray)
Generally it is best to avoid using the copy constructor of an btAlignedObjectArray, and use a (const) reference to the array instead.
void resize(int newsize, const T &fillData=T())
btAlignedObjectArray< T > & operator=(const btAlignedObjectArray< T > &other)
int findBinarySearch(const T &key) const
non-recursive binary search, assumes sorted array
T & expand(const T &fillValue=T())
pointer allocate(size_type n, const_pointer *hint=0)
T & expandNonInitializing()
void quickSortInternal(const L &CompareFunc, int lo, int hi)
void quickSort(const L &CompareFunc)