17 #ifndef BT_OBJECT_ARRAY__
18 #define BT_OBJECT_ARRAY__
29 #define BT_USE_PLACEMENT_NEW 1
31 #define BT_ALLOW_ARRAY_COPY_OPERATOR // enabling this can accidently perform deep copies of data if you are not careful
36 #endif //BT_USE_MEMCPY
38 #ifdef BT_USE_PLACEMENT_NEW
40 #endif //BT_USE_PLACEMENT_NEW
57 #ifdef BT_ALLOW_ARRAY_COPY_OPERATOR
64 #else//BT_ALLOW_ARRAY_COPY_OPERATOR
67 #endif//BT_ALLOW_ARRAY_COPY_OPERATOR
72 return (size ? size*2 : 1);
77 for (i=start;i<end;++i)
79 new (&dest[i]) T(m_data[i]);
82 #endif //BT_USE_PLACEMENT_NEW
96 for (i=first; i<last;i++)
141 int otherSize = otherArray.
size();
143 otherArray.
copy(0, otherSize, m_data);
205 if (newsize >
size())
214 const register int curSize =
size();
216 if (newsize < curSize)
218 for(
int i = newsize; i < curSize; i++)
224 if (newsize > curSize)
228 #ifdef BT_USE_PLACEMENT_NEW
229 for (
int i=curSize;i<newsize;i++)
231 new ( &m_data[i]) T(fillData);
233 #endif //BT_USE_PLACEMENT_NEW
241 const register int sz =
size();
254 const register int sz =
size();
260 #ifdef BT_USE_PLACEMENT_NEW
261 new (&m_data[sz]) T(fillValue);
270 const register int sz =
size();
276 #ifdef BT_USE_PLACEMENT_NEW
277 new ( &m_data[
m_size] ) T(_Val);
279 m_data[
size()] = _Val;
280 #endif //BT_USE_PLACEMENT_NEW
326 template <
typename L>
332 T x=m_data[(lo+hi)/2];
337 while (CompareFunc(m_data[i],x))
339 while (CompareFunc(x,m_data[j]))
356 template <
typename L>
368 template <
typename L>
369 void downHeap(T *pArr,
int k,
int n,
const L& CompareFunc)
374 T temp = pArr[k - 1];
380 if ((child < n) && CompareFunc(pArr[child - 1] , pArr[child]))
385 if (CompareFunc(temp , pArr[child - 1]))
388 pArr[k - 1] = pArr[child - 1];
399 void swap(
int index0,
int index1)
402 char temp[
sizeof(T)];
403 memcpy(temp,&m_data[index0],
sizeof(T));
404 memcpy(&m_data[index0],&m_data[index1],
sizeof(T));
405 memcpy(&m_data[index1],temp,
sizeof(T));
407 T temp = m_data[index0];
408 m_data[index0] = m_data[index1];
409 m_data[index1] = temp;
410 #endif //BT_USE_PLACEMENT_NEW
414 template <
typename L>
420 for (k = n/2; k > 0; k--)
422 downHeap(m_data, k, n, CompareFunc);
433 downHeap(m_data, 1, n, CompareFunc);
444 while (first <= last) {
445 int mid = (first + last) / 2;
446 if (key > m_data[mid])
448 else if (key < m_data[mid])
462 for (i=0;i<
size();i++)
464 if (m_data[i] == key)
473 void remove(
const T& key)
477 if (findIndex<
size())
488 m_ownsMemory =
false;
496 int otherSize = otherArray.
size();
498 otherArray.
copy(0, otherSize, m_data);
503 #endif //BT_OBJECT_ARRAY__
void copy(int start, int end, T *dest) const
void push_back(const T &_Val)
void deallocate(pointer ptr)
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
const T & at(int n) 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)
#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.
int size() const
return the number of elements in the array
#define BT_USE_PLACEMENT_NEW
If the platform doesn't support placement new, you can disable BT_USE_PLACEMENT_NEW then the btAligne...
void initializeFromBuffer(void *buffer, int size, int capacity)
int capacity() const
return the pre-allocated (reserved) elements, this is at least as large as the total number of elemen...
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())
int findLinearSearch(const T &key) const
btAlignedObjectArray< T > & operator=(const btAlignedObjectArray< T > &other)
T & expand(const T &fillValue=T())
pointer allocate(size_type n, const_pointer *hint=0)
T & expandNonInitializing()
int findBinarySearch(const T &key) const
non-recursive binary search, assumes sorted array
btAlignedAllocator< T, 16 > m_allocator
void quickSortInternal(const L &CompareFunc, int lo, int hi)
bool operator()(const T &a, const T &b)
void quickSort(const L &CompareFunc)