Commit 2dd13cfe authored by berenger-bramas's avatar berenger-bramas

Use memset to init array

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/scalfmm/scalfmm/trunk@413 2616d619-271b-44dc-8df4-d4a8f33a7222
parent 951c9fa9
...@@ -183,15 +183,15 @@ public: ...@@ -183,15 +183,15 @@ public:
this->cells = new CellClass**[this->subOctreeHeight]; this->cells = new CellClass**[this->subOctreeHeight];
fassert(this->cells, "Allocation failled", __LINE__, __FILE__); fassert(this->cells, "Allocation failled", __LINE__, __FILE__);
memset(this->cells, 0, sizeof(CellClass**) * subOctreeHeight);
// We start at a sub-level - 8^1 // We start at a sub-level - 8^1
int cellsAtlevel = 8; int cellsAtlevel = 8;
for( int indexLevel = 0 ; indexLevel < this->subOctreeHeight ; ++indexLevel ){ for( int indexLevel = 0 ; indexLevel < this->subOctreeHeight ; ++indexLevel ){
this->cells[indexLevel] = new CellClass*[cellsAtlevel]; this->cells[indexLevel] = new CellClass*[cellsAtlevel];
fassert(this->cells[indexLevel], "Allocation failled", __LINE__, __FILE__); fassert(this->cells[indexLevel], "Allocation failled", __LINE__, __FILE__);
for( int indexCells = 0 ; indexCells < cellsAtlevel ; ++indexCells ){ memset(this->cells[indexLevel], 0, sizeof(CellClass*) * cellsAtlevel);
this->cells[indexLevel][indexCells] = 0;
}
cellsAtlevel <<= 3; // => * 8 >> 8^indexLevel cellsAtlevel <<= 3; // => * 8 >> 8^indexLevel
} }
...@@ -329,6 +329,7 @@ public: ...@@ -329,6 +329,7 @@ public:
template< class ParticleClass, class CellClass , class ContainerClass, class LeafClass> template< class ParticleClass, class CellClass , class ContainerClass, class LeafClass>
class FSubOctreeWithLeafs : public FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass> { class FSubOctreeWithLeafs : public FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass> {
private: private:
typedef FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass> Parent;
LeafClass** leafs; //< Leafs array LeafClass** leafs; //< Leafs array
...@@ -353,17 +354,14 @@ public: ...@@ -353,17 +354,14 @@ public:
this->leafs = new LeafClass*[cellsAtLeafLevel]; this->leafs = new LeafClass*[cellsAtLeafLevel];
fassert(this->leafs, "Allocation failled", __LINE__, __FILE__); fassert(this->leafs, "Allocation failled", __LINE__, __FILE__);
for( int indexLeaf = 0 ; indexLeaf < cellsAtLeafLevel ; ++indexLeaf ){ memset(leafs, 0, sizeof(LeafClass*) * cellsAtLeafLevel);
this->leafs[indexLeaf] = 0;
}
} }
/** /**
* Destructor dealloc all leafs & the leaf array * Destructor dealloc all leafs & the leaf array
*/ */
virtual ~FSubOctreeWithLeafs(){ virtual ~FSubOctreeWithLeafs(){
const int cellsAtLeafLevel = 1 << (3 * this->subOctreeHeight ); for( int indexLeaf = Parent::leftLeafIndex ; indexLeaf <= Parent::rightLeafIndex ; ++indexLeaf ){
for( int indexLeaf = 0 ; indexLeaf < cellsAtLeafLevel ; ++indexLeaf ){
if(this->leafs[indexLeaf]){ if(this->leafs[indexLeaf]){
delete this->leafs[indexLeaf]; delete this->leafs[indexLeaf];
} }
...@@ -376,12 +374,12 @@ public: ...@@ -376,12 +374,12 @@ public:
*/ */
void insert(const MortonIndex index, const FTreeCoordinate& host, const ParticleClass& inParticle, const int inTreeHeight){ void insert(const MortonIndex index, const FTreeCoordinate& host, const ParticleClass& inParticle, const int inTreeHeight){
// Get the morton index for the leaf level // Get the morton index for the leaf level
const MortonIndex arrayIndex = FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass>::getLeafIndex(index,inTreeHeight); const MortonIndex arrayIndex = Parent::getLeafIndex(index,inTreeHeight);
// is there already a leaf? // is there already a leaf?
if( !this->leafs[arrayIndex] ){ if( !this->leafs[arrayIndex] ){
this->leafs[arrayIndex] = new LeafClass(); this->leafs[arrayIndex] = new LeafClass();
FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass>::newLeafInserted( int(arrayIndex) , index, host); Parent::newLeafInserted( int(arrayIndex) , index, host);
} }
// add particle to leaf list // add particle to leaf list
this->leafs[arrayIndex]->push(inParticle); this->leafs[arrayIndex]->push(inParticle);
...@@ -392,13 +390,13 @@ public: ...@@ -392,13 +390,13 @@ public:
*/ */
bool removeLeaf(const MortonIndex index, const int inTreeHeight) { bool removeLeaf(const MortonIndex index, const int inTreeHeight) {
// Get the morton index for the leaf level // Get the morton index for the leaf level
const MortonIndex arrayIndex = FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass>::getLeafIndex(index,inTreeHeight); const MortonIndex arrayIndex = Parent::getLeafIndex(index,inTreeHeight);
if( this->leafs[arrayIndex] ){ if( this->leafs[arrayIndex] ){
// remove container // remove container
delete this->leafs[arrayIndex]; delete this->leafs[arrayIndex];
this->leafs[arrayIndex] = 0; this->leafs[arrayIndex] = 0;
return FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass>::removeCellsFromLeaf( int(arrayIndex) ); return Parent::removeCellsFromLeaf( int(arrayIndex) );
} }
return false; return false;
} }
...@@ -462,7 +460,9 @@ public: ...@@ -462,7 +460,9 @@ public:
template< class ParticleClass, class CellClass , class ContainerClass, class LeafClass> template< class ParticleClass, class CellClass , class ContainerClass, class LeafClass>
class FSubOctree : public FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass> { class FSubOctree : public FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass> {
private: private:
FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass>** subleafs; //< Last levels is composed of suboctree typedef FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass> Parent;
Parent** subleafs; //< Last levels is composed of suboctree
/** Disable copy */ /** Disable copy */
FSubOctree(const FSubOctree&){} FSubOctree(const FSubOctree&){}
...@@ -481,20 +481,18 @@ public: ...@@ -481,20 +481,18 @@ public:
FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass>(inParent, inIndexInParent, inSubOctreeHeight, inSubOctreePosition, false) { FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass>(inParent, inIndexInParent, inSubOctreeHeight, inSubOctreePosition, false) {
const int cellsAtLeafLevel = 1 << (3 * inSubOctreeHeight); const int cellsAtLeafLevel = 1 << (3 * inSubOctreeHeight);
this->subleafs = new FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass>*[cellsAtLeafLevel];
this->subleafs = new Parent*[cellsAtLeafLevel];
fassert(this->subleafs, "Allocation failled", __LINE__, __FILE__); fassert(this->subleafs, "Allocation failled", __LINE__, __FILE__);
for( int indexLeaf = 0 ; indexLeaf < cellsAtLeafLevel ; ++indexLeaf ){ memset(subleafs, 0, sizeof(Parent**) * cellsAtLeafLevel);
this->subleafs[indexLeaf] = 0;
}
} }
/** /**
* Destructor dealloc all suboctrees leafs & leafs array * Destructor dealloc all suboctrees leafs & leafs array
*/ */
virtual ~FSubOctree(){ virtual ~FSubOctree(){
const int cellsAtLeafLevel = 1 << (3 * this->subOctreeHeight); for( int indexLeaf = Parent::leftLeafIndex ; indexLeaf <= Parent::rightLeafIndex ; ++indexLeaf ){
for( int indexLeaf = 0 ; indexLeaf < cellsAtLeafLevel ; ++indexLeaf ){
if(this->subleafs[indexLeaf]) delete this->subleafs[indexLeaf]; if(this->subleafs[indexLeaf]) delete this->subleafs[indexLeaf];
} }
delete [] this->subleafs; delete [] this->subleafs;
...@@ -506,7 +504,7 @@ public: ...@@ -506,7 +504,7 @@ public:
void insert(const MortonIndex index, const FTreeCoordinate& host, const ParticleClass& inParticle, const int inTreeHeight){ void insert(const MortonIndex index, const FTreeCoordinate& host, const ParticleClass& inParticle, const int inTreeHeight){
// We need the morton index at the bottom level of this sub octree // We need the morton index at the bottom level of this sub octree
// so we remove the right side // so we remove the right side
const MortonIndex arrayIndex = FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass>::getLeafIndex(index,inTreeHeight); const MortonIndex arrayIndex = Parent::getLeafIndex(index,inTreeHeight);
// Is there already a leaf? // Is there already a leaf?
if( !this->subleafs[arrayIndex] ){ if( !this->subleafs[arrayIndex] ){
// We need to create leaf sub octree // We need to create leaf sub octree
...@@ -528,7 +526,7 @@ public: ...@@ -528,7 +526,7 @@ public:
host.getZ() >> (inTreeHeight - nextSubOctreePosition )); host.getZ() >> (inTreeHeight - nextSubOctreePosition ));
// We need to inform parent class // We need to inform parent class
FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass>::newLeafInserted( int(arrayIndex), index >> (3 * (inTreeHeight-nextSubOctreePosition) ), hostAtLevel); Parent::newLeafInserted( int(arrayIndex), index >> (3 * (inTreeHeight-nextSubOctreePosition) ), hostAtLevel);
} }
// Ask next suboctree to insert the particle // Ask next suboctree to insert the particle
this->subleafs[arrayIndex]->insert( index, host, inParticle, inTreeHeight); this->subleafs[arrayIndex]->insert( index, host, inParticle, inTreeHeight);
...@@ -539,13 +537,13 @@ public: ...@@ -539,13 +537,13 @@ public:
*/ */
bool removeLeaf(const MortonIndex index, const int inTreeHeight) { bool removeLeaf(const MortonIndex index, const int inTreeHeight) {
// Get the morton index for the leaf level // Get the morton index for the leaf level
const MortonIndex arrayIndex = FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass>::getLeafIndex(index,inTreeHeight); const MortonIndex arrayIndex = Parent::getLeafIndex(index,inTreeHeight);
if( this->subleafs[arrayIndex]->removeLeaf(index, inTreeHeight) ){ if( this->subleafs[arrayIndex]->removeLeaf(index, inTreeHeight) ){
// remove container // remove container
delete this->subleafs[arrayIndex]; delete this->subleafs[arrayIndex];
this->subleafs[arrayIndex] = 0; this->subleafs[arrayIndex] = 0;
return FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass>::removeCellsFromLeaf( int(arrayIndex) ); return Parent::removeCellsFromLeaf( int(arrayIndex) );
} }
return false; return false;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment