16#ifndef BT_OBJECT_ARRAY__
17#define BT_OBJECT_ARRAY__
28#define BT_USE_PLACEMENT_NEW 1
30#define BT_ALLOW_ARRAY_COPY_OPERATOR
37#ifdef BT_USE_PLACEMENT_NEW
55#ifdef BT_ALLOW_ARRAY_COPY_OPERATOR
75 for (
i = start;
i < end; ++
i)
77 new (&dest[
i])
T(m_data[
i]);
94 for (
i = first;
i < last;
i++)
103 return m_allocator.allocate(
size);
114 m_allocator.deallocate(m_data);
136 int otherSize = otherArray.
size();
138 otherArray.
copy(0, otherSize, m_data);
196 if (newsize >
size())
205 const int curSize =
size();
207 if (newsize < curSize)
209 for (
int i = newsize;
i < curSize;
i++)
216 if (newsize > curSize)
220#ifdef BT_USE_PLACEMENT_NEW
221 for (
int i = curSize;
i < newsize;
i++)
223 new (&m_data[
i])
T(fillData);
232 const int sz =
size();
244 const int sz =
size();
250#ifdef BT_USE_PLACEMENT_NEW
251 new (&m_data[sz])
T(fillValue);
259 const int sz =
size();
265#ifdef BT_USE_PLACEMENT_NEW
266 new (&m_data[m_size])
T(_Val);
268 m_data[
size()] = _Val;
310 template <
typename L>
316 T x = m_data[(lo + hi) / 2];
321 while (CompareFunc(m_data[
i],
x))
323 while (CompareFunc(
x, m_data[j]))
340 template <
typename L>
351 template <
typename L>
357 T temp = pArr[k - 1];
363 if ((child < n) && CompareFunc(pArr[child - 1], pArr[child]))
368 if (CompareFunc(temp, pArr[child - 1]))
371 pArr[k - 1] = pArr[child - 1];
382 void swap(
int index0,
int index1)
385 char temp[
sizeof(
T)];
386 memcpy(temp, &m_data[index0],
sizeof(
T));
387 memcpy(&m_data[index0], &m_data[index1],
sizeof(
T));
388 memcpy(&m_data[index1], temp,
sizeof(
T));
390 T temp = m_data[index0];
391 m_data[index0] = m_data[index1];
392 m_data[index1] = temp;
396 template <
typename L>
402 for (k = n / 2; k > 0; k--)
404 downHeap(m_data, k, n, CompareFunc);
414 downHeap(m_data, 1, n, CompareFunc);
422 int last =
size() - 1;
425 while (first <= last)
427 int mid = (first + last) / 2;
428 if (key > m_data[mid])
430 else if (key < m_data[mid])
445 if (m_data[
i] == key)
463 if (m_data[
i] == key)
490 m_ownsMemory =
false;
498 int otherSize = otherArray.
size();
500 otherArray.
copy(0, otherSize, m_data);
#define BT_USE_PLACEMENT_NEW
#define SIMD_FORCE_INLINE
bool operator()(const T &a, const T &b) const
SIMD_FORCE_INLINE void reserve(int _Count)
int findLinearSearch2(const T &key) const
SIMD_FORCE_INLINE void clear()
clear the array, deallocated memory. Generally it is better to use array.resize(0),...
void copyFromArray(const btAlignedObjectArray &otherArray)
SIMD_FORCE_INLINE T & expand(const T &fillValue=T())
SIMD_FORCE_INLINE int capacity() const
return the pre-allocated (reserved) elements, this is at least as large as the total number of elemen...
int findLinearSearch(const T &key) const
SIMD_FORCE_INLINE void resizeNoInitialize(int newsize)
SIMD_FORCE_INLINE int size() const
SIMD_FORCE_INLINE void init()
SIMD_FORCE_INLINE const T & operator[](int n) const
void swap(int index0, int index1)
SIMD_FORCE_INLINE void pop_back()
void removeAtIndex(int index)
void remove(const T &key)
SIMD_FORCE_INLINE void resize(int newsize, const T &fillData=T())
SIMD_FORCE_INLINE void destroy(int first, int last)
SIMD_FORCE_INLINE btAlignedObjectArray< T > & operator=(const btAlignedObjectArray< T > &other)
SIMD_FORCE_INLINE T & at(int n)
void quickSort(const L &CompareFunc)
void heapSort(const L &CompareFunc)
void initializeFromBuffer(void *buffer, int size, int capacity)
SIMD_FORCE_INLINE T & expandNonInitializing()
int findBinarySearch(const T &key) const
non-recursive binary search, assumes sorted array
SIMD_FORCE_INLINE void * allocate(int size)
SIMD_FORCE_INLINE void deallocate()
SIMD_FORCE_INLINE const T & at(int n) const
SIMD_FORCE_INLINE void push_back(const T &_Val)
SIMD_FORCE_INLINE T & operator[](int n)
btAlignedObjectArray(const btAlignedObjectArray &otherArray)
Generally it is best to avoid using the copy constructor of an btAlignedObjectArray,...
SIMD_FORCE_INLINE void copy(int start, int end, T *dest) const
SIMD_FORCE_INLINE int allocSize(int size)
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 quickSortInternal(const L &CompareFunc, int lo, int hi)