49class spursAlignedObjectArray
58 SIMD_FORCE_INLINE
int allocSize(
int size)
60 return (size ? size*2 : 1);
62 SIMD_FORCE_INLINE
void copy(
int start,
int end, T* dest)
65 for (i=start;i<end;++i)
66#ifdef BT_USE_PLACEMENT_NEW
67 new (&dest[i]) T(m_data[i]);
73 SIMD_FORCE_INLINE
void init()
79 SIMD_FORCE_INLINE
void destroy(
int first,
int last)
82 for (i=first; i<last;i++)
88 SIMD_FORCE_INLINE
void* allocate(
int size)
91 return m_allocator.allocate(size);
95 SIMD_FORCE_INLINE
void deallocate()
98 m_allocator.deallocate(m_data);
108 spursAlignedObjectArray()
113 ~spursAlignedObjectArray()
118 SIMD_FORCE_INLINE
int capacity()
const
123 SIMD_FORCE_INLINE
int size()
const
128 SIMD_FORCE_INLINE
const T& operator[](
int n)
const
133 SIMD_FORCE_INLINE T& operator[](
int n)
139 SIMD_FORCE_INLINE
void clear()
148 SIMD_FORCE_INLINE
void pop_back()
154 SIMD_FORCE_INLINE
void resize(
int newsize,
const T& fillData=T())
156 int curSize = size();
158 if (newsize < size())
160 for(
int i = curSize; i < newsize; i++)
166 if (newsize > size())
170#ifdef BT_USE_PLACEMENT_NEW
171 for (
int i=curSize;i<newsize;i++)
173 new ( &m_data[i]) T(fillData);
183 SIMD_FORCE_INLINE T& expand(
const T& fillValue=T())
186 if( sz == capacity() )
188 reserve( allocSize(size()) );
191#ifdef BT_USE_PLACEMENT_NEW
192 new (&m_data[sz]) T(fillValue);
199 SIMD_FORCE_INLINE
void push_back(
const T& _Val)
202 if( sz == capacity() )
204 reserve( allocSize(size()) );
207#ifdef BT_USE_PLACEMENT_NEW
208 new ( &m_data[m_size] ) T(_Val);
210 m_data[size()] = _Val;
218 SIMD_FORCE_INLINE
void reserve(
int _Count)
220 if (capacity() < _Count)
222 T* s = (T*)allocate(_Count);
242 bool operator() (
const T& a,
const T& b )
250 template <
typename L>
256 T temp = pArr[k - 1];
262 if ((child < n) && CompareFunc(pArr[child - 1] , pArr[child]))
267 if (CompareFunc(temp , pArr[child - 1]))
270 pArr[k - 1] = pArr[child - 1];
281 void swap(
int index0,
int index1)
284 char temp[
sizeof(T)];
285 memcpy(temp,&m_data[index0],
sizeof(T));
286 memcpy(&m_data[index0],&m_data[index1],
sizeof(T));
287 memcpy(&m_data[index1],temp,
sizeof(T));
289 T temp = m_data[index0];
290 m_data[index0] = m_data[index1];
291 m_data[index1] = temp;
296 template <
typename L>
297 void heapSort(L CompareFunc)
302 for (k = n/2; k > 0; k--)
304 downHeap(m_data, k, n, CompareFunc);
315 downHeap(m_data, 1, n, CompareFunc);
326 while (first <= last) {
327 int mid = (first + last) / 2;
328 if (key > m_data[mid])
330 else if (key < m_data[mid])
339 int findLinearSearch(
const T& key)
const
344 for (i=0;i<size();i++)
346 if (m_data[i] == key)
355 void remove(
const T& key)
358 int findIndex = findLinearSearch(key);
359 if (findIndex<size())
361 swap( findIndex,size()-1);
int findBinarySearch(const T &key) const
non-recursive binary search, assumes sorted array
Definition spursAlignedObjectArray.h:320
void downHeap(T *pArr, int k, int n, L CompareFunc)
heap sort from http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Sort/Heap/
Definition spursAlignedObjectArray.h:251