void MEDCouplingSkyLineArray::deleteSimplePack(const int idx)
{
- using namespace std;
-
validIndex("deleteSimplePack", idx);
int* iP(_index->getPointer());
- const int start = iP[idx], end = iP[idx+1];
+ const int start(iP[idx]), end(iP[idx+1]);
// _values
- int initValSz = _values->getNbOfElems();
- int deltaSz = start-end; // should be negative
+ int initValSz( _values->getNbOfElems() );
+ int deltaSz( start-end ); // should be negative
int *vP(_values->getPointer());
- if (deltaSz < 0){
- copy(vP+end, vP+initValSz, vP+start);
+ if (deltaSz < 0)
+ {
+ std::copy(vP+end, vP+initValSz, vP+start);
_values->reAlloc(initValSz+deltaSz);
- }
+ }
else
throw INTERP_KERNEL::Exception("MEDCouplingSkyLineArray::deleteSimplePack");
-
// _index
- int nt = _index->getNbOfElems();
- copy(iP+idx+1, iP+nt, iP+idx);
+ int nt(_index->getNbOfElems());
+ std::copy(iP+idx+1, iP+nt, iP+idx);
for(int ii = idx; ii < nt-1; ii++)
iP[ii] += deltaSz;
_index->reAlloc(nt-1);
if (idx->empty())
return;
- for (auto id = idx->begin(); id != idx->end(); id++)
+ for (const int * id = idx->begin(); id != idx->end(); id++)
validIndex("deleteSimplePacks", *id);
if (idx->getNbOfElems() != packs.size())
throw INTERP_KERNEL::Exception("MEDCouplingSkyLineArray::deleteSimplePacks: size of list of pack is incorrect");
// copy _index, _values into a deque<set<int>>
- std::deque<std::set<int>> valuesByIdx;
+ std::deque< std::set<int> > valuesByIdx;
int* vP(_values->getPointer());
int* iP(_index->getPointer());
- int nt = _index->getNbOfElems();
+ std::size_t nt ( _index->getNbOfElems() );
for (int ii = 0; ii < nt-1; ii++)
valuesByIdx.push_back(std::set<int>(vP+iP[ii], vP+iP[ii+1]));
// modify the deque<set<int>> according to idx and packs
- int ii = 0;
- for (auto id = idx->begin(); id != idx->end(); id++){
+ int ii(0);
+ for (const int *id = idx->begin(); id != idx->end(); id++)
+ {
valuesByIdx[*id] = std::set<int>(packs[ii]->begin(), packs[ii]->end());
ii++;
- }
-
+ }
// copy back the deque<set<int>> into _index, _values
- int valSz = 0;
+ int valSz(0);
*iP = 0;
- for (auto values : valuesByIdx){
- valSz += values.size();
+ for (std::deque< std::set<int> >::const_iterator values=valuesByIdx.begin();values!=valuesByIdx.end();values++)
+ {
+ valSz += (*values).size();
*(++iP) = valSz;
- }
-
+ }
_values->reAlloc(valSz);
iP = _index->getPointer();
vP = _values->getPointer();
- for (auto values : valuesByIdx){
- copy(values.begin(), values.end(), vP+(*iP));
+ for (auto values : valuesByIdx)
+ {
+ std::copy(values.begin(), values.end(), vP+(*iP));
iP++;
- }
-
+ }
}
void MEDCouplingSkyLineArray::deleteSimplePacks(const DataArrayInt* idx){
int* iP(_index->getPointer());
int initValSz = _values->getNbOfElems();
int *vP(_values->getPointer());
- int end_prec = 0;
- int start_prec = 0;
- for (auto ii : packsToDelete){
- int start = iP[ii];
+ int end_prec(0),start_prec(0);
+ for(std::set<int>::const_iterator ii=packsToDelete.begin();ii!=packsToDelete.end();ii++)
+ {
+ int start = iP[*ii];
if (end_prec != 0)
- copy(vP+end_prec, vP+start, vP+start_prec);
+ copy(vP+end_prec, vP+start, vP+start_prec);
start_prec += start-end_prec;
- end_prec = iP[ii+1];
- }
+ end_prec = iP[*ii+1];
+ }
if (end_prec != 0)
- copy(vP+end_prec, vP+initValSz, vP+start_prec);
+ copy(vP+end_prec, vP+initValSz, vP+start_prec);
_values->reAlloc(initValSz-(end_prec-start_prec));
// _index
end_prec = 0;
start_prec = 0;
int deleted = 0;
- for (auto ii : packsToDelete){
- if (end_prec != 0){
- copy(iP+end_prec, iP+ii, iP+start_prec);
- for (int i=start_prec; i<ii; i++)
- iP[i] -= offset;
- }
- offset += iP[ii+1] - iP[ii];
- start_prec = ii-deleted;
- end_prec = ii+1;
+ for(std::set<int>::const_iterator ii=packsToDelete.begin();ii!=packsToDelete.end();ii++)
+ {
+ if (end_prec != 0)
+ {
+ copy(iP+end_prec, iP+*ii, iP+start_prec);
+ for (int i=start_prec; i<*ii; i++)
+ iP[i] -= offset;
+ }
+ offset += iP[*ii+1] - iP[*ii];
+ start_prec = *ii-deleted;
+ end_prec = *ii+1;
deleted += 1;
- }
- if (end_prec != 0){
+ }
+ if (end_prec != 0)
+ {
copy(iP+end_prec, iP+nt, iP+start_prec);
for (int i=start_prec; i<nt; i++)
- iP[i] -= offset;
- }
+ iP[i] -= offset;
+ }
_index->reAlloc(nt-deleted);
}
level3(self)
gtumesh(self)
pass
+
+ def testSKLAReplaceDeletePacks(self):
+ index=DataArrayInt([0,3,5,6,6])
+ value=DataArrayInt([1,2,3, 2,3, 3 ])
+ sla=MEDCouplingSkyLineArray(index,value)
+ idx=DataArrayInt([0,3])
+ packs=[DataArrayInt([4,5]),DataArrayInt([6,7,8])]
+ sla.replaceSimplePacks(idx,packs)
+ self.assertTrue(sla.getIndexArray().isEqual(DataArrayInt([0,2,4,5,8])))
+ self.assertTrue(sla.getValuesArray().isEqual(DataArrayInt([4,5, 2,3, 3, 6,7,8])))
+ sla.deleteSimplePacks(idx)
+ self.assertTrue(sla.getIndexArray().isEqual(DataArrayInt([0,2,3])))
+ self.assertTrue(sla.getValuesArray().isEqual(DataArrayInt([2,3, 3])))
+ sla.deleteSimplePack(1)
+ self.assertTrue(sla.getIndexArray().isEqual(DataArrayInt([0,2])))
+ self.assertTrue(sla.getValuesArray().isEqual(DataArrayInt([2,3])))
+ pass
+
pass
if __name__ == '__main__':