 |
Newton Dynamics
4.00
|
|
27 #ifndef __ND_ARRAY_H__
28 #define __ND_ARRAY_H__
30 #include "ndCoreStdafx.h"
35 #include "ndClassAlloc.h"
99 void CopyData(T*
const dst,
const T*
const src, ndInt32 elements);
135 Resize(source.m_capacity);
137 for (ndInt32 i = 0; i < source.m_size; ++i)
139 m_array[i] = source[i];
157 ndAssert(i < m_size);
165 ndAssert(i < m_size);
172 ndAssert(m_size <= m_capacity);
173 if (m_size == m_capacity)
175 Resize(m_capacity * 2);
177 m_array[m_size] = element;
190 while (count > m_capacity)
192 Resize(m_capacity * 2);
206 const ndInt32 sizeInBytes = ndInt32 (elements *
sizeof(T));
207 const ndInt32 size16 = ndInt32(sizeInBytes /
sizeof(
ndVector));
211 for (ndInt32 i = 0; i < size16; ++i)
215 char*
const dstBytes = (
char*)dst;
216 const char*
const srcBytes = (
char*)src;
217 for (ndInt32 i = ndInt32(size16 *
sizeof(
ndVector)); i < sizeInBytes; ++i)
219 dstBytes[i] = srcBytes[i];
234 if (newSize > m_capacity || (m_capacity == 0))
236 newSize = ndMax(newSize, 16);
240 CopyData(newArray, m_array, m_size);
244 m_capacity = newSize;
246 else if (newSize < m_capacity)
248 newSize = ndMax(newSize, 16);
252 CopyData(newArray, m_array, newSize);
257 m_capacity = newSize;
264 ndSwap(m_array, other.m_array);
265 ndSwap(m_size, other.m_size);
266 ndSwap(m_capacity, other.m_capacity);
273 m_capacity = size + 1;
274 m_array = (T*)memory;
288 const ndInt32 size = ndMin (count, GetCount());
289 for (ndInt32 i = size - 1; i != 0; --i)
291 ndUnsigned32 j = ndUnsigned32(ndRandInt()) % size;
292 ndSwap (m_array[i], m_array[j]);
Base class for providing memory allocation for all other engine classes.
Definition: ndClassAlloc.h:30
static D_CORE_API void * Malloc(size_t size)
General Memory allocation function.
Definition: ndMemory.cpp:46
Generic template vector.
Definition: ndArray.h:42
void Swap(ndArray &other)
Interchange all the information with other.
Definition: ndArray.h:262
ndArray()
constructor, set count and capacity to zero, not memory is allocated.
Definition: ndArray.h:108
void PushBack(const T &element)
Add element to the end of the buffer.
Definition: ndArray.h:170
void RandomShuffle(ndInt32 count)
Randomize the vector entries.
Definition: ndArray.h:286
void ResetMembers()
set all member to 0.
Definition: ndArray.h:278
ndInt32 GetCount() const
return the size of the array.
Definition: ndArray.h:182
ndArray(ndInt32 count)
constructor, set count and capacity, allocated space for count elements.
Definition: ndArray.h:117
void Resize(ndInt32 count)
Set a new size.
Definition: ndArray.h:224
void SetMembers(ndInt32 size, void *const memory)
assign all members.
Definition: ndArray.h:270
ndArray(const ndArray &source)
copy constructor, allocate and copy only m_size elements from source.
Definition: ndArray.h:127
~ndArray()
deallocate all memory, dos not call destructor on any of th elements.
Definition: ndArray.h:145
ndInt32 GetCapacity() const
return the capacity of the array.
Definition: ndArray.h:198
void SetCount(ndInt32 count)
Set a new size.
Definition: ndArray.h:188
T & operator[](ndInt32 i)
Get the i element for the array.
Definition: ndArray.h:162
Definition: ndVectorArmNeon.h:41
static D_CORE_API void Free(void *const ptr)
Destroy a memory buffer previously allocated by Malloc.
Definition: ndMemory.cpp:61