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 54 #ifdef BT_ALLOW_ARRAY_COPY_OPERATOR 61 #else //BT_ALLOW_ARRAY_COPY_OPERATOR 64 #endif //BT_ALLOW_ARRAY_COPY_OPERATOR 69 return (size ? size * 2 : 1);
74 for (i = start; i < end; ++i)
76 new (&dest[i]) T(m_data[i]);
79 #endif //BT_USE_PLACEMENT_NEW 93 for (i = first; i < last; i++) {
132 int32_t otherSize = otherArray.
size();
134 otherArray.
copy(0, otherSize, m_data);
192 int32_t curSize =
size();
194 if (newsize < curSize) {
195 for (int32_t i = newsize; i < curSize; i++) {
200 if (newsize >
size()) {
203 #ifdef BT_USE_PLACEMENT_NEW 204 for (int32_t i = curSize; i < newsize; i++) {
205 new (&m_data[i]) T(fillData);
207 #endif //BT_USE_PLACEMENT_NEW 231 #ifdef BT_USE_PLACEMENT_NEW 232 new (&m_data[sz]) T(fillValue);
245 #ifdef BT_USE_PLACEMENT_NEW 246 new (&m_data[m_size]) T(_Val);
248 m_data[
size()] = _Val;
249 #endif //BT_USE_PLACEMENT_NEW 288 template <
typename L>
293 int32_t i = lo, j = hi;
294 T
x = m_data[(lo + hi) / 2];
298 while (CompareFunc(m_data[i], x))
300 while (CompareFunc(x, m_data[j]))
316 template <
typename L>
326 template <
typename L>
327 void downHeap(T* pArr, int32_t k, int32_t n,
const L& CompareFunc)
332 T temp = pArr[k - 1];
335 int32_t child = 2 * k;
337 if ((child < n) && CompareFunc(pArr[child - 1], pArr[child])) {
341 if (CompareFunc(temp, pArr[child - 1])) {
343 pArr[k - 1] = pArr[child - 1];
353 void swap(int32_t index0, int32_t index1)
356 char temp[
sizeof(T)];
357 memcpy(temp, &m_data[index0],
sizeof(T));
358 memcpy(&m_data[index0], &m_data[index1],
sizeof(T));
359 memcpy(&m_data[index1], temp,
sizeof(T));
361 T temp = m_data[index0];
362 m_data[index0] = m_data[index1];
363 m_data[index1] = temp;
364 #endif //BT_USE_PLACEMENT_NEW 367 template <
typename L>
373 for (k = n / 2; k > 0; k--) {
374 downHeap(m_data, k, n, CompareFunc);
383 downHeap(m_data, 1, n, CompareFunc);
391 int32_t last =
size() - 1;
394 while (first <= last) {
395 int32_t mid = (first + last) / 2;
396 if (key > m_data[mid])
398 else if (key < m_data[mid])
408 int32_t index =
size();
411 for (i = 0; i <
size(); i++) {
412 if (m_data[i] == key) {
420 void remove(
const T& key)
424 if (findIndex <
size()) {
434 m_ownsMemory =
false;
442 int32_t otherSize = otherArray.
size();
444 otherArray.
copy(0, otherSize, m_data);
448 #endif //BT_OBJECT_ARRAY__ void quickSortInternal(const L &CompareFunc, int32_t lo, int32_t hi)
Definition: btAlignedObjectArray.h:289
void quickSort(const L &CompareFunc)
Definition: btAlignedObjectArray.h:317
SIMD_FORCE_INLINE T & expand(const T &fillValue=T())
Definition: btAlignedObjectArray.h:224
Definition: btAlignedObjectArray.h:45
SIMD_FORCE_INLINE const btScalar & x() const
Return the x value.
Definition: btVector3.h:275
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.
Definition: btAlignedObjectArray.h:128
SIMD_FORCE_INLINE int32_t size() const
return the number of elements in the array
Definition: btAlignedObjectArray.h:138
void deallocate(pointer ptr)
Definition: btAlignedAllocator.h:88
btAlignedObjectArray()
Definition: btAlignedObjectArray.h:117
SIMD_FORCE_INLINE void pop_back()
Definition: btAlignedObjectArray.h:181
SIMD_FORCE_INLINE T & at(int32_t n)
Definition: btAlignedObjectArray.h:150
int32_t findLinearSearch(const T &key) const
Definition: btAlignedObjectArray.h:406
SIMD_FORCE_INLINE int32_t capacity() const
return the pre-allocated (reserved) elements, this is at least as large as the total number of elemen...
Definition: btAlignedObjectArray.h:255
void downHeap(T *pArr, int32_t k, int32_t n, const L &CompareFunc)
heap sort from http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Sort/Heap/
Definition: btAlignedObjectArray.h:327
pointer allocate(size_type n, const_pointer *hint=0)
Definition: btAlignedAllocator.h:82
SIMD_FORCE_INLINE const T & at(int32_t n) const
Definition: btAlignedObjectArray.h:143
~btAlignedObjectArray()
Definition: btAlignedObjectArray.h:122
void copyFromArray(const btAlignedObjectArray &otherArray)
Definition: btAlignedObjectArray.h:440
#define btAssert(x)
Definition: btScalar.h:188
void initializeFromBuffer(void *buffer, int32_t size, int32_t capacity)
Definition: btAlignedObjectArray.h:431
bool operator()(const T &a, const T &b)
Definition: btAlignedObjectArray.h:282
void swap(int32_t index0, int32_t index1)
Definition: btAlignedObjectArray.h:353
int32_t findBinarySearch(const T &key) const
non-recursive binary search, assumes sorted array
Definition: btAlignedObjectArray.h:388
SIMD_FORCE_INLINE int32_t allocSize(int32_t size)
Definition: btAlignedObjectArray.h:67
SIMD_FORCE_INLINE const T & operator[](int32_t n) const
Definition: btAlignedObjectArray.h:157
SIMD_FORCE_INLINE void init()
Definition: btAlignedObjectArray.h:82
Definition: btAlignedObjectArray.h:280
SIMD_FORCE_INLINE btAlignedObjectArray< T > & operator=(const btAlignedObjectArray< T > &other)
Definition: btAlignedObjectArray.h:56
#define SIMD_FORCE_INLINE
Definition: btScalar.h:173
SIMD_FORCE_INLINE void destroy(int32_t first, int32_t last)
Definition: btAlignedObjectArray.h:90
SIMD_FORCE_INLINE void push_back(const T &_Val)
Definition: btAlignedObjectArray.h:238
SIMD_FORCE_INLINE void reserve(int32_t _Count)
Definition: btAlignedObjectArray.h:260
SIMD_FORCE_INLINE void deallocate()
Definition: btAlignedObjectArray.h:105
void heapSort(const L &CompareFunc)
Definition: btAlignedObjectArray.h:368
SIMD_FORCE_INLINE void copy(int32_t start, int32_t end, T *dest) const
Definition: btAlignedObjectArray.h:71
SIMD_FORCE_INLINE 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.
Definition: btAlignedObjectArray.h:172
SIMD_FORCE_INLINE void resize(int32_t newsize, const T &fillData=T())
Definition: btAlignedObjectArray.h:190
#define BT_USE_PLACEMENT_NEW
Definition: btAlignedObjectArray.h:28
SIMD_FORCE_INLINE T & operator[](int32_t n)
Definition: btAlignedObjectArray.h:164
SIMD_FORCE_INLINE void * allocate(int32_t size)
Definition: btAlignedObjectArray.h:98
SIMD_FORCE_INLINE T & expandNonInitializing()
Definition: btAlignedObjectArray.h:213