|
**************************************************************************************************/ cp_bool DyArrayDelete(DyArray* pArr, cp_int32 nIndex) { cp_int32 i; //if the input parameter is invalid, return. if(!pArr) { return CP_FALSE; } //destroy the element with destroy function. if(pArr->m_fDestroy) { pArr->m_fDestroy(pArr->m_ppData[nIndex]); } //move the elements after 'nIndex' to the previous one. for(i = nIndex; (i+1) < pArr->m_nSize; i++) { pArr->m_ppData[i] = pArr->m_ppData[i+1]; } //set the last one to null. pArr->m_ppData[i] = NULL; pArr->m_nSize--; //if need ,shrink the size. DyArrayShrink(pArr); return CP_TRUE; } /************************************************************************************************** 【函数名】: DyArrayDeleteEx 【描述】:删除元素by index (扩展) 【参数】: pArr: the array's address. nIndex: the position in the array to delete useless data. nEdn: 【返回值】:ture 或者false ***************************************************************************************************/ cp_bool DyArrayDeleteEx(DyArray* pArr, cp_int32 nBegin,cp_int32 nEnd) { cp_int32 i,nLen = 0; //if the input parameter is invalid, return. //if(!pArr && nBegin>nEnd && nBegin<0 && nBegin>=pArr->m_nSize && nEnd<0 && nEnd>=pArr->m_nSize) if(!pArr) { return CP_FALSE; } //destroy the element with destroy function. if(pArr->m_fDestroy) { for(i=nBegin; i<=nEnd; i++) { pArr->m_fDestroy(pArr->m_ppData[i]); } } //move the elements after 'nIndex' to the previous one. nLen = nEnd - nBegin + 1; for(i = nBegin; (i+nLen) < pArr->m_nSize; i++) { pArr->m_ppData[i] = pArr->m_ppData[i+nLen]; } //set the last one to null. //pArr->m_ppData[i] = NULL; pArr->m_nSize -= nLen; //if need ,shrink the size. DyArrayShrink(pArr); return CP_TRUE; } /************************************************************************************************** 【函数名】: DyArrayReset 【描述】:清除数组数据,缩减数组到原始大小 【参数】: pArr: the array's address. 【返回值】: none. ***************************************************************************************************/ void DyArrayReset(DyArray* pArr) { cp_int32 i; void** pData = NULL; //if the input parameter is invalid, return. if(!pArr) { return; } //reset all the elements with destroy function. if(pArr->m_fDestroy) { for(i=0; i
m_nSize;i++) { pArr->m_fDestroy(pArr->m_ppData[i]); } } pArr->m_nSize = 0; //if need, shrink the size. if(pArr->m_nAllocSize > MIN_PRE_ALLOCATE_SIZE) { pData = (void**)REALLOCFUN(pArr->m_ppData, sizeof(void*) * MIN_PRE_ALLOCATE_SIZE); if(pData != NULL) { pArr->m_ppData = pData; pArr->m_nAllocSize = MIN_PRE_ALLOCATE_SIZE; } if(pArr->m_ppData) { MEMSETFUN(pArr->m_ppData,0,sizeof(void*)*pArr->m_nAllocSize); } } } /************************************************************************************************** 【函数名】: DyArrayClear 【描述】:清除数组数据,不缩减数组到原始大小 【参数】: pArr: the array's address. 【返回值】:NA ***************************************************************************************************/ void DyArrayClear(DyArray* pArr) { cp_int32 i; void** pData = NULL; //if the input parameter is invalid, return. if(!pArr) { return; } //reset all the elements with destroy function. if(pArr->m_fDestroy) { for(i=0; i
m_nSize;i++) { pArr->m_fDestroy(pArr->m_ppData[i]); } } pArr->m_nSize = 0; } /************************************************************************************************** 【函数名】: DyArrayResetCustom 【描述】:清除数组使用用户函数,缩减数组到原始大小 |