61 m_nCurrentSize = nInitialSize;
64 for (
int i = 0; i < nInitialSize; i++)
70 for (
int i = 0; i < m_nElements; i++)
71 if (m_ppElements[i]->bDelete)
72 delete m_ppElements[i];
74 delete [] m_ppElements;
85 m_ppElements[nElement]->
bDelete =
false;
90 for (
int i = 0; i < m_nElements; i++)
92 if (m_ppElements[i]->bDelete)
93 delete m_ppElements[i];
102 void CDynamicArray::SetSize(
int nSize)
104 if (nSize <= m_nCurrentSize)
106 printf(
"error: tried to set size smaller than current size in CDynamicArray::SetSize\n");
110 m_nCurrentSize = nSize;
116 for (i = 0; i < m_nElements; i++)
117 ppElements[i] = m_ppElements[i];
119 for (i = m_nElements; i < nSize; i++)
122 delete [] m_ppElements;
123 m_ppElements = ppElements;
131 if (m_nElements > (m_nCurrentSize * 3 / 4))
132 SetSize(m_nCurrentSize * 2);
134 pElement->
bDelete = bManageMemory;
135 m_ppElements[m_nElements++] = pElement;
142 if (nIndex < 0 || nIndex >= m_nElements)
145 delete m_ppElements[nIndex];
146 m_ppElements[nIndex] = 0;
148 for (
int i = nIndex; i < m_nElements - 1; i++)
149 m_ppElements[i] = m_ppElements[i + 1];
158 int nIndex = _FindFirstMatch(pElement);
170 int nIndex, nElementsDeleted = 0;
172 while ((nIndex = _FindFirstMatch(pElement)) != -1)
178 return nElementsDeleted;
183 for (
int i = 0; i < m_nElements; i++)
186 return m_ppElements[i];
194 for (
int i = 0; i < m_nElements; i++)
205 float best_error = 9999999;
208 for (
int i = 0; i < m_nElements; i++)
210 const float error = pElement->
Error(m_ppElements[i]);
212 if (error < best_error)
222 fResultError = best_error;
224 return m_ppElements[best_i];
bool AddElement(CDynamicArrayElement *pElement, bool bAddUniqueOnly=false, bool bManageMemory=true)
CDynamicArrayElement * FindBestMatch(const CDynamicArrayElement *pElement, float &fResultError)
CDynamicArray(int nInititalSize)
int DeleteAllMatches(const CDynamicArrayElement *pElement)
CDynamicArrayElement * FindFirstMatch(const CDynamicArrayElement *pElement)
void DontManageMemory(int nElement)
int DeleteFirstMatch(const CDynamicArrayElement *pElement)
virtual bool Equivalent(const CDynamicArrayElement *pElement) const
bool DeleteElement(int nIndex)
virtual float Error(const CDynamicArrayElement *pElement) const