Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[all] Replace find by contains #5215

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ void DirectSAPNarrowPhase::cacheData()
data.doesBoxSelfCollide = lastCollisionModel->getSelfCollision();
data.isBoxSimulated = lastCollisionModel->isSimulated();
data.collisionElementIterator = box.cube.getExternalChildren().first;
data.isInBroadPhase = (m_broadPhaseCollisionModels.find(firstCollisionModel) != m_broadPhaseCollisionModels.end() );
data.isInBroadPhase = m_broadPhaseCollisionModels.contains(firstCollisionModel);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void IncrSAP::reinit()

inline bool IncrSAP::added(core::CollisionModel *cm) const
{
return collisionModels.count(cm->getLast()) >= 1;
return collisionModels.contains(cm->getLast());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ sofa::helper::OptionsGroup CollisionResponse::initializeResponseOptions(sofa::co
}

sofa::helper::OptionsGroup responseOptions(listResponse);
if (listResponse.find("PenalityContactForceField") != listResponse.end())
if (listResponse.contains("PenalityContactForceField"))
responseOptions.setSelectedItem("PenalityContactForceField");

return responseOptions;
Expand Down Expand Up @@ -210,7 +210,7 @@ CollisionResponse::removeInactiveContacts(const core::collision::ContactManager:
core::collision::Contact::SPtr contact = contactIt->second;
dmsg_error_when(contact == nullptr) << "Checking if inactive on invalid contact";

if (outputsMap.find(contactIt->first) == outputsMap.end())
if (!outputsMap.contains(contactIt->first))
{
//contact is not found among the result of the collision detection during this time step
//the contact comes from a previous time step
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class SOFA_COMPONENT_COLLISION_RESPONSE_CONTACT_API RuleBasedContactManager : pu
}
else
{
if ( model1->getGroups().count(group1)==0 )
if (!model1->getGroups().contains(group1) )
return false;
}
if (!name2.empty())
Expand All @@ -96,7 +96,7 @@ class SOFA_COMPONENT_COLLISION_RESPONSE_CONTACT_API RuleBasedContactManager : pu
}
else
{
if ( model2->getGroups().count(group2)==0 )
if (!model2->getGroups().contains(group2) )
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ void Distances< DataTypes >::computeGeodesicalDistance ( const unsigned int& map
const core::topology::BaseMeshTopology::HexaID& hexaID = hexaCoord.first;
const double& distance = hexaCoord.second;

if ( hexasParsed.find ( hexaID ) != hexasParsed.end() ) continue;
if ( hexasParsed.contains ( hexaID )) continue;
hexasParsed.insert ( hexaID ); // This hexa has been parsed

// Continue if the distance max is reached
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void ExtrudeSurface<DataTypes>::doUpdate()
//a table is also used to map old vertex indices with the new set of indices
for (unsigned int i=0 ; i<3 ; i++)
{
if (pointMatching.find(triangle[i]) == pointMatching.end())
if (!pointMatching.contains(triangle[i]))
{
extrusionVertices->push_back(surfaceVertices[triangle[i]]);
extrusionVertices->push_back(surfaceVertices[triangle[i]] + normals[triangle[i]].first*heightFactor.getValue());
Expand Down Expand Up @@ -152,9 +152,9 @@ void ExtrudeSurface<DataTypes>::doUpdate()

for (unsigned int i=0 ; i<3 ; i++)
{
if ( edgesOnBorder.find(e[i]) == edgesOnBorder.end())
if (!edgesOnBorder.contains(e[i]))
{
if ( edgesOnBorder.find(ei[i]) == edgesOnBorder.end())
if (!edgesOnBorder.contains(ei[i]))
edgesOnBorder[e[i]] = true;
else
edgesOnBorder[ei[i]] = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,11 @@ void GenerateCylinder<DataTypes>::doUpdate()
// check if a triangle with an opposite orientation already exists
Triangle tr = Triangle(v[0], v[2], v[1]);

if (triangleMap.find(tr) == triangleMap.end())
if (!triangleMap.contains(tr))
{
// triangle not in triangleMap so create a new one
tr = Triangle(v[0], v[1], v[2]);
if (triangleMap.find(tr) == triangleMap.end())
if (!triangleMap.contains(tr))
{
triangleMap[tr] = triangleRank++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void MeshTetraStuffing::doUpdate()
std::set< int > tris;
for (unsigned int i=0; i<results.size(); ++i)
{
if (tris.find(results[i].tid) != tris.end())
if (tris.contains(results[i].tid))
{
if (i < results.size()-1)
results[i] = results[results.size()-1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class SelectConnectedLabelsROI : public sofa::core::DataEngine
for(unsigned int l2=0; l2<nb && !connected;l2++)
if(l1!=l2)
for(size_t i2=0; i2<(*labels[l2])[i].size() && !connected;i2++)
if(connectS.find(TPair((*labels[l1])[i][i1],(*labels[l2])[i][i2]))!=connectS.end())
if(connectS.contains(TPair((*labels[l1])[i][i1],(*labels[l2])[i][i2])))
connected=true;
if(connected)
indices.push_back((sofa::Index)i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class SelectLabelROI : public sofa::core::DataEngine
for(sofa::Index i=0; i<nb;i++)
{
for(size_t j=0; j<labels[i].size();j++)
if(selectLabelsSet.find(labels[i][j])!=selectLabelsSet.end())
if(selectLabelsSet.contains(labels[i][j]))
{
indices.push_back(i);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void GridMeshCreator::doClearBuffers()

void GridMeshCreator::insertUniqueEdge( unsigned a, unsigned b )
{
if( uniqueEdges.find(Edge(b,a))==uniqueEdges.end() ) // symmetric not found
if(!uniqueEdges.contains(Edge(b,a)) ) // symmetric not found
uniqueEdges.insert(Edge(a,b)); // redundant elements are automatically pruned
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ bool MeshGmshLoader::readGmsh(std::ifstream &file, const unsigned int gmshFormat
size_t v1 = std::max(nodes[edgesInQuadraticTriangle[j][0]],
nodes[edgesInQuadraticTriangle[j][1]]);
Edge e(v0, v1);
if (edgeSet.find(e) == edgeSet.end()) {
if (!edgeSet.contains(e)) {
edgeSet.insert(e);
addEdge(my_edges.wref(), v0, v1);
hoep[0] = nodes[j + 3];
Expand All @@ -362,7 +362,7 @@ bool MeshGmshLoader::readGmsh(std::ifstream &file, const unsigned int gmshFormat
size_t v1 = std::max(nodes[edgesInQuadraticTetrahedron[j][0]],
nodes[edgesInQuadraticTetrahedron[j][1]]);
Edge e(v0, v1);
if (edgeSet.find(e) == edgeSet.end()) {
if (!edgeSet.contains(e)) {
edgeSet.insert(e);
addEdge(my_edges.wref(), v0, v1);
hoep[0] = nodes[j + 4];
Expand Down Expand Up @@ -543,7 +543,7 @@ bool MeshGmshLoader::readGmsh(std::ifstream &file, const unsigned int gmshFormat
size_t v1 = std::max(nodes[edgesInQuadraticTriangle[j][0]],
nodes[edgesInQuadraticTriangle[j][1]]);
Edge e(v0, v1);
if (edgeSet.find(e) == edgeSet.end())
if (!edgeSet.contains(e))
{
edgeSet.insert(e);
addEdge(my_edges.wref(), v0, v1);
Expand All @@ -568,7 +568,7 @@ bool MeshGmshLoader::readGmsh(std::ifstream &file, const unsigned int gmshFormat
size_t v1 = std::max(nodes[edgesInQuadraticTetrahedron[j][0]],
nodes[edgesInQuadraticTetrahedron[j][1]]);
Edge e(v0, v1);
if (edgeSet.find(e) == edgeSet.end())
if (!edgeSet.contains(e))
{
edgeSet.insert(e);
addEdge(my_edges.wref(), v0, v1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ bool MeshOBJLoader::readOBJ (std::ifstream &file, const char* filename)
if (vsplit)
{
vertPosIdx[j] = i;
if (normMap.count(n))
if (normMap.contains(n))
vertNormIdx[j] = normMap[n];
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ bool MeshVTKLoader::setInputsMesh()
sofa::Index v1 = std::max( inFP[i + edgesInQuadraticTriangle[j][0]],
inFP[i + edgesInQuadraticTriangle[j][1]]);
Edge e(v0, v1);
if (edgeSet.find(e) == edgeSet.end())
if (!edgeSet.contains(e))
{
edgeSet.insert(e);
addEdge(my_edges.wref(), v0, v1);
Expand All @@ -457,7 +457,7 @@ bool MeshVTKLoader::setInputsMesh()
sofa::Index v1 = std::max( inFP[i + edgesInQuadraticTetrahedron[j][0]],
inFP[i + edgesInQuadraticTetrahedron[j][1]]);
Edge e(v0, v1);
if (edgeSet.find(e) == edgeSet.end())
if (!edgeSet.contains(e))
{
edgeSet.insert(e);
addEdge(my_edges.wref(), v0, v1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void VoxelGridLoader::reinit()
{
// add only points that were used above
const unsigned int pidx = i + j * numPointsX + k * numPointsX * numPointsY;
if ( keepPoint.find ( pidx ) != keepPoint.end() )
if ( keepPoint.contains ( pidx ))
{
renumberingMap[pidx] = pointIdx;
auto& pnt = seqPoints[pointIdx];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API EigenSolverFactory
template<class Scalar>
bool hasObject(const std::string& orderingMethodName )
{
return m_registeredTypes.find(join<Scalar>(orderingMethodName)) != m_registeredTypes.end();
return m_registeredTypes.contains(join<Scalar>(orderingMethodName));
}

[[nodiscard]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ bool MappingGraph::hasAnyMappingInput(core::behavior::BaseMechanicalState* mstat
}

//only main (non mapped) mechanical states are in this map
return m_positionInGlobalMatrix.find(mstate) == m_positionInGlobalMatrix.end();
return !m_positionInGlobalMatrix.contains(mstate);
}

bool MappingGraph::hasAnyMappingInput(core::behavior::BaseForceField* forceField) const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void LineSetSkinningMapping<TIn, TOut>::init()

while (linesInfluencedByVertice[verticeIndex].size() < numberInfluencedLines.getValue() && lineInfluencedIndex < lines.size())
{
if (neighborhood[max].count(lines[lineInfluencedIndex].lineIndex) != 0)
if (neighborhood[max].contains(lines[lineInfluencedIndex].lineIndex))
{
sumWeights += lines[lineInfluencedIndex].weight;
linesInfluencedByVertice[verticeIndex].push_back(lines[lineInfluencedIndex]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void APIVersion::checkInputData()

const auto & API_version = d_level.getValue();
static const std::set<std::string> allowedAPIVersions { "17.06", "17.12", "18.06", "18.12", "19.06", "19.12", "20.06", "20.12", SOFA_VERSION_STR } ;
if( allowedAPIVersions.find(API_version) == std::cend(allowedAPIVersions) )
if(!allowedAPIVersions.contains(API_version))
{
const auto allowedVersionStr = std::accumulate(std::next(allowedAPIVersions.begin()), allowedAPIVersions.end(), *(allowedAPIVersions.begin()), [](const std::string & s, const std::string & v) {
return s + ", " + v;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ void MeshSpringForceField<DataTypes>::addSpring(std::set<std::pair<sofa::Index,

if (m1<m2)
{
if (sset.count(std::make_pair(m1,m2))>0) return;
if (sset.contains(std::make_pair(m1,m2))) return;
sset.insert(std::make_pair(m1,m2));
}
else
{
if (sset.count(std::make_pair(m2,m1))>0) return;
if (sset.contains(std::make_pair(m2,m1))) return;
sset.insert(std::make_pair(m2,m1));
}
const Real l = ((mstate2->read(core::vec_id::read_access::restPosition)->getValue())[m2] - (mstate1->read(core::vec_id::read_access::restPosition)->getValue())[m1]).norm();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void QuadBendingSprings<DataTypes>::addSpring( unsigned a, unsigned b, std::set<
if ((int)a > d_localRange.getValue()[1] && (int)b > d_localRange.getValue()[1]) return;
}
const IndexPair ab(a<b?a:b, a<b?b:a);
if (springSet.find(ab) != springSet.end()) return;
if (springSet.contains(ab)) return;
springSet.insert(ab);
const VecCoord& x =this->mstate1->read(core::vec_id::read_access::position)->getValue();
Real s = (Real)this->d_ks.getValue()[0];
Expand All @@ -73,7 +73,7 @@ void QuadBendingSprings<DataTypes>::registerEdge( IndexPair ab, IndexPair cd, st
ab = std::make_pair(ab.second,ab.first);
cd = std::make_pair(cd.second,cd.first);
}
if (edgeMap.find(ab) == edgeMap.end())
if (!edgeMap.contains(ab))
{
edgeMap[ab] = cd;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void TriangleBendingSprings<DataTypes>::registerTriangle( unsigned a, unsigned b
{
const IndexPair edge(a<b ? a : b,a<b ? b : a);
const unsigned opposite = c;
if( edgeMap.find( edge ) == edgeMap.end() )
if(!edgeMap.contains( edge ))
{
edgeMap[edge] = opposite;
}
Expand All @@ -73,7 +73,7 @@ void TriangleBendingSprings<DataTypes>::registerTriangle( unsigned a, unsigned b
{
const IndexPair edge(b<c ? b : c,b<c ? c : b);
const unsigned opposite = a;
if( edgeMap.find( edge ) == edgeMap.end() )
if(!edgeMap.contains( edge ))
{
edgeMap[edge] = opposite;
}
Expand All @@ -87,7 +87,7 @@ void TriangleBendingSprings<DataTypes>::registerTriangle( unsigned a, unsigned b
{
const IndexPair edge(c<a ? c : a,c<a ? a : c);
const unsigned opposite = b;
if( edgeMap.find( edge ) == edgeMap.end() )
if(!edgeMap.contains( edge ))
{
edgeMap[edge] = opposite;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2397,7 +2397,7 @@ std::list< core::behavior::BaseMechanicalState::ConstraintBlock > MechanicalObje
for( ; chunk != chunkEnd ; chunk++)
{
const unsigned int column = chunk.index();
if( blocks.find( column ) == blocks.end() )
if(!blocks.contains( column ))
{
// nope: let's create it
matrix_t* mat = new matrix_t(linearalgebra::BaseMatrix::Index(indices.size()), linearalgebra::BaseMatrix::Index(dimensionDeriv));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void HexahedronSetTopologyContainer::createEdgeSetArray()
PointID v2 = t[edgesInHexahedronArray[j][1]];
const Edge e((v1<v2) ? Edge(v1,v2) : Edge(v2,v1));

if(edgeMap.find(e)==edgeMap.end())
if(!edgeMap.contains(e))
{
// edge not in edgeMap so create a new one
const size_t edgeIndex = edgeMap.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ MultilevelHexahedronSetTopologyContainer::getHexaChildren(const Index hexaId,

for(Size i=0; i<_fineComponents.getValue().size(); ++i)
{
if(compSet.find(_fineComponents.getValue()[i]) != compSet.end())
if(compSet.contains(_fineComponents.getValue()[i]))
children.push_back(i);
}

Expand Down Expand Up @@ -498,7 +498,7 @@ void MultilevelHexahedronSetTopologyContainer::Component::removeVoxels(const std

bool MultilevelHexahedronSetTopologyContainer::Component::hasVoxel(const Vec3i& voxel) const
{
return (this->_voxels.find(voxel) != this->_voxels.end());
return this->_voxels.contains(voxel);
}

bool MultilevelHexahedronSetTopologyContainer::Component::isEmpty() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void QuadSetTopologyContainer::createEdgeSetArray()
// sort vertices in lexicographic order
const Edge e = ((v1<v2) ? Edge(v1,v2) : Edge(v2,v1));

if(edgeMap.find(e) == edgeMap.end())
if(!edgeMap.contains(e))
{
// edge not in edgeMap so create a new one
const EdgeID edgeIndex = (EdgeID)edgeMap.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void TetrahedronSetTopologyContainer::createEdgeSetArray()
// sort vertices in lexicographic order
const Edge e((v1<v2) ? Edge(v1,v2) : Edge(v2,v1));

if (edgeMap.find(e)==edgeMap.end())
if (!edgeMap.contains(e))
{
// edge not in edgeMap so create a new one
const size_t edgeIndex = edgeMap.size();
Expand Down Expand Up @@ -222,7 +222,7 @@ void TetrahedronSetTopologyContainer::createEdgesInTetrahedronArray()
// sort vertices in lexicographic order
const Edge e((v1<v2) ? Edge(v1,v2) : Edge(v2,v1));

if (edgeMap.find(e)==edgeMap.end())
if (!edgeMap.contains(e))
{
// edge not in edgeMap so create a new one
const size_t edgeIndex = edgeMap.size();
Expand Down Expand Up @@ -277,11 +277,11 @@ void TetrahedronSetTopologyContainer::createTriangleSetArray()
// check if a triangle with an opposite orientation already exists
Triangle tr = Triangle(v[0], v[2], v[1]);

if (triangleMap.find(tr) == triangleMap.end())
if (!triangleMap.contains(tr))
{
// triangle not in triangleMap so create a new one
tr = Triangle(v[0], v[1], v[2]);
if (triangleMap.find(tr) == triangleMap.end())
if (!triangleMap.contains(tr))
{
triangleMap[tr] = (TriangleID)m_triangle.size();
m_triangle.push_back(tr);
Expand Down
Loading
Loading