diff --git a/applications/test/HashSet/Test-hashSet.C b/applications/test/HashSet/Test-hashSet.C index eeae7ff0d0b44e3e9471fda74b00d6b5b9036ed8..5316f05e3f74270504697a14a52ec6dba38559c4 100644 --- a/applications/test/HashSet/Test-hashSet.C +++ b/applications/test/HashSet/Test-hashSet.C @@ -188,10 +188,10 @@ int main(int argc, char *argv[]) Info<< "setB : " << setB << endl; labelPair pair(12, 15); - setB.set(pair); + setB.setMany(pair); Info<< "setB : " << setB << endl; - setB.unset(pair); + setB.unsetMany(pair); labelHashSet setC(1); @@ -257,7 +257,7 @@ int main(int argc, char *argv[]) someLst[elemI] = elemI*elemI; } - label added = setD.set(someLst); + label added = setD.setMany(someLst); Info<< "added " << added << " from " << someLst.size() << endl; Info<< "setD : " << flatOutput(setD) << endl; diff --git a/applications/test/edges/Test-edges.C b/applications/test/edges/Test-edges.C index 51da417de3e53e7ce1652ffcbc207ddc4f286ab4..68de5446ee60d33a8872a619cd8b201dca55534f 100644 --- a/applications/test/edges/Test-edges.C +++ b/applications/test/edges/Test-edges.C @@ -94,7 +94,7 @@ int main(int argc, char *argv[]) e4.start() = e4.end() = -1; Info<< "insert from list\n"; labelHashSet newIndices({2, -1, 2, 1, 4, 1, 2, 3}); - e4.insert(newIndices.toc()); + e4.insertMany(newIndices.toc()); printInfo(e4); e4.start() = e4.end() = -1; @@ -105,12 +105,12 @@ int main(int argc, char *argv[]) FixedList<label, 8> otherIndices{12, 2, -1, 1, 4, 1, 2, 3}; e4.start() = e4.end() = -1; Info<< "insert from list: " << otherIndices << nl; - e4.insert(otherIndices); + e4.insertMany(otherIndices); printInfo(e4); e4.start() = e4.end(); Info<< "erase from list: " << otherIndices << nl; - Info<< "removed " << e4.erase(otherIndices) << " values" << nl; + Info<< "removed " << e4.eraseMany(otherIndices) << " values" << nl; printInfo(e4); for (label i : {-1, 0, 1, 3}) diff --git a/applications/test/sizeof/Test-sizeof.C b/applications/test/sizeof/Test-sizeof.C index 93358f7af7bf0cccde3ec1b9f1f1d7564e8f5f90..40f33de650bc7752f9af1cbcb6ecb878e135359d 100644 --- a/applications/test/sizeof/Test-sizeof.C +++ b/applications/test/sizeof/Test-sizeof.C @@ -32,6 +32,8 @@ Description #include "dictionary.H" #include "nil.H" #include "IOstreams.H" +#include "PstreamBuffers.H" +#include "Time.H" namespace Foam { @@ -101,6 +103,9 @@ int main(int argc, char *argv[]) cout<<"string:" << sizeof(Foam::string) << nl; } + cout<<"IOstream:" << sizeof(Foam::IOstream) << nl; + cout<<"PstreamBuffers:" << sizeof(Foam::PstreamBuffers) << nl; + cout<<"Time:" << sizeof(Foam::Time) << nl; Info << "---\nEnd\n" << endl; diff --git a/applications/utilities/mesh/advanced/refineWallLayer/refineWallLayer.C b/applications/utilities/mesh/advanced/refineWallLayer/refineWallLayer.C index aac1d730d5a92aa091936b6a762910ccf376426a..f01fa003e44158b4c3553c4fef8e527a965e744c 100644 --- a/applications/utilities/mesh/advanced/refineWallLayer/refineWallLayer.C +++ b/applications/utilities/mesh/advanced/refineWallLayer/refineWallLayer.C @@ -122,10 +122,7 @@ int main(int argc, char *argv[]) const labelList& pCells = mesh.pointCells()[meshPointi]; - forAll(pCells, pCelli) - { - cutCells.insert(pCells[pCelli]); - } + cutCells.insertMany(pCells); } } diff --git a/applications/utilities/mesh/advanced/refinementLevel/refinementLevel.C b/applications/utilities/mesh/advanced/refinementLevel/refinementLevel.C index 463d1b689e7f692e136325bbeb644f80c0f70137..468ede34537e56c9330fe84f9e1844bcf36ab3f5 100644 --- a/applications/utilities/mesh/advanced/refinementLevel/refinementLevel.C +++ b/applications/utilities/mesh/advanced/refinementLevel/refinementLevel.C @@ -184,11 +184,7 @@ int main(int argc, char *argv[]) const DynamicList<label>& bin = bins[binI]; cellSet cells(mesh, "vol" + name(binI), bin.size()); - - forAll(bin, i) - { - cells.insert(bin[i]); - } + cells.insertMany(bin); Info<< " " << lowerLimits[binI] << " .. " << upperLimits[binI] << " : writing " << bin.size() << " cells to cellSet " diff --git a/applications/utilities/mesh/advanced/splitCells/splitCells.C b/applications/utilities/mesh/advanced/splitCells/splitCells.C index 96028a969e422d51de3ddda004bec7589162234d..6bd54ba6d9c478e9f6e60b659b9cbb61f4687421 100644 --- a/applications/utilities/mesh/advanced/splitCells/splitCells.C +++ b/applications/utilities/mesh/advanced/splitCells/splitCells.C @@ -633,10 +633,7 @@ int main(int argc, char *argv[]) ); cellSet cutSet(mesh, "cutSet", cutCells.size()); - forAll(cutCells, i) - { - cutSet.insert(cutCells[i]); - } + cutSet.insertMany(cutCells); // Gets cuts across cells from cuts through edges. Info<< "Writing " << cutSet.size() << " cells to cut to cellSet " diff --git a/applications/utilities/mesh/conversion/ideasUnvToFoam/ideasUnvToFoam.C b/applications/utilities/mesh/conversion/ideasUnvToFoam/ideasUnvToFoam.C index 621ced981d471472437ff9e515fe961ba94afa36..021ac49b8756d984a25c74ec119be6d01d09c205 100644 --- a/applications/utilities/mesh/conversion/ideasUnvToFoam/ideasUnvToFoam.C +++ b/applications/utilities/mesh/conversion/ideasUnvToFoam/ideasUnvToFoam.C @@ -956,11 +956,7 @@ int main(int argc, char *argv[]) forAll(dofVertIndices, patchi) { const labelList& foamVerts = dofVertIndices[patchi]; - - forAll(foamVerts, i) - { - dofGroups[patchi].insert(foamVerts[i]); - } + dofGroups[patchi].insertMany(foamVerts); } List<DynamicList<face>> dynPatchFaces(dofVertIndices.size()); diff --git a/applications/utilities/mesh/conversion/writeMeshObj/writeMeshObj.C b/applications/utilities/mesh/conversion/writeMeshObj/writeMeshObj.C index 9e7f4f424c59c1e492e8e62d22dd8c576b01964d..3e06227f01c61b72c607d288123df85fa87bc57a 100644 --- a/applications/utilities/mesh/conversion/writeMeshObj/writeMeshObj.C +++ b/applications/utilities/mesh/conversion/writeMeshObj/writeMeshObj.C @@ -344,10 +344,7 @@ void writePointCells { const labelList& cEdges = mesh.cellEdges()[pCells[i]]; - forAll(cEdges, i) - { - allEdges.insert(cEdges[i]); - } + allEdges.insertMany(cEdges); } diff --git a/applications/utilities/mesh/generation/extrude/extrudeMesh/extrudeMesh.C b/applications/utilities/mesh/generation/extrude/extrudeMesh/extrudeMesh.C index 6f16a6beb5ad8e21e4e48fd22d503ef01a286e72..1c0d36af43967567cdc8963ca6b85bac9cc7acb4 100644 --- a/applications/utilities/mesh/generation/extrude/extrudeMesh/extrudeMesh.C +++ b/applications/utilities/mesh/generation/extrude/extrudeMesh/extrudeMesh.C @@ -795,10 +795,7 @@ int main(int argc, char *argv[]) forAll(addedCells, facei) { const labelList& aCells = addedCells[facei]; - forAll(aCells, i) - { - addedCellsSet.insert(aCells[i]); - } + addedCellsSet.insertMany(aCells); } } } diff --git a/applications/utilities/mesh/generation/extrude/extrudeToRegionMesh/extrudeToRegionMesh.C b/applications/utilities/mesh/generation/extrude/extrudeToRegionMesh/extrudeToRegionMesh.C index 22277cabc8e2bfdf125dd5c3357025518a7ad706..dd1830e4c26e77014b2379a651d119a7fd63f1f3 100644 --- a/applications/utilities/mesh/generation/extrude/extrudeToRegionMesh/extrudeToRegionMesh.C +++ b/applications/utilities/mesh/generation/extrude/extrudeToRegionMesh/extrudeToRegionMesh.C @@ -527,10 +527,7 @@ label findUncoveredPatchFace { // Make set of extruded faces. labelHashSet extrudeFaceSet(extrudeMeshFaces.size()); - forAll(extrudeMeshFaces, i) - { - extrudeFaceSet.insert(extrudeMeshFaces[i]); - } + extrudeFaceSet.insertMany(extrudeMeshFaces); const polyBoundaryMesh& pbm = mesh.boundaryMesh(); const labelList& eFaces = mesh.edgeFaces()[meshEdgeI]; @@ -564,10 +561,7 @@ label findUncoveredCyclicPatchFace { // Make set of extruded faces. labelHashSet extrudeFaceSet(extrudeMeshFaces.size()); - forAll(extrudeMeshFaces, i) - { - extrudeFaceSet.insert(extrudeMeshFaces[i]); - } + extrudeFaceSet.insertMany(extrudeMeshFaces); const polyBoundaryMesh& pbm = mesh.boundaryMesh(); const labelList& eFaces = mesh.edgeFaces()[meshEdgeI]; diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshCalcDualMesh.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshCalcDualMesh.C index 5cfd3efee7fbef27de8226a46f55280a4d6fff14..bc7cd7f7ad3e7e2fdae987a25d021eda8e81593f 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshCalcDualMesh.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshCalcDualMesh.C @@ -1053,10 +1053,7 @@ Foam::labelHashSet Foam::conformalVoronoiMesh::checkPolyMeshQuality nInvalidPolyhedra++; - forAll(cells[cI], cFI) - { - wrongFaces.insert(cells[cI][cFI]); - } + wrongFaces.insertMany(cells[cI]); } } @@ -1096,11 +1093,7 @@ Foam::labelHashSet Foam::conformalVoronoiMesh::checkPolyMeshQuality if (nInternalFaces[cI] <= 1) { oneInternalFaceCells++; - - forAll(cells[cI], cFI) - { - wrongFaces.insert(cells[cI][cFI]); - } + wrongFaces.insertMany(cells[cI]); } } @@ -1132,13 +1125,8 @@ Foam::labelHashSet Foam::conformalVoronoiMesh::checkPolyMeshQuality // forAll(f, fPtI) // { // label ptI = f[fPtI]; - // const labelList& pC = ptCells[ptI]; - - // forAll(pC, pCI) - // { - // limitCells.insert(pC[pCI]); - // } + // limitCells.insertMany(pC); // } // } diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C index f18bb544dc7929d3de89596adc6bd5ef0ffa15d8..63d7542ceef1b70990ec4144f91f708e6a73e3b8 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C @@ -1366,15 +1366,10 @@ Foam::labelHashSet Foam::conformalVoronoiMesh::findRemainingProtrusionSet mesh.nCells()/1000 ); - forAllConstIter(labelHashSet, protrudingBoundaryPoints, iter) + for (const label pointi : protrudingBoundaryPoints) { - const label pointi = iter.key(); const labelList& pCells = mesh.pointCells()[pointi]; - - forAll(pCells, pCI) - { - protrudingCells.insert(pCells[pCI]); - } + protrudingCells.insertMany(pCells); } label protrudingCellsSize = protrudingCells.size(); diff --git a/applications/utilities/mesh/manipulation/refineMesh/refineMesh.C b/applications/utilities/mesh/manipulation/refineMesh/refineMesh.C index 94ec49005b9020d9480c58650411f5aae73a8502..367e62392a47c687bcea1f9069239c0ccb40e9cb 100644 --- a/applications/utilities/mesh/manipulation/refineMesh/refineMesh.C +++ b/applications/utilities/mesh/manipulation/refineMesh/refineMesh.C @@ -349,11 +349,7 @@ int main(int argc, char *argv[]) forAll(oldToNew, oldCelli) { const labelList& added = oldToNew[oldCelli]; - - forAll(added, i) - { - newCells.insert(added[i]); - } + newCells.insertMany(added); } Info<< "Writing refined cells (" diff --git a/applications/utilities/mesh/manipulation/splitMesh/regionSide.C b/applications/utilities/mesh/manipulation/splitMesh/regionSide.C index fb7c83057335c30a3d236f7302626d910b397fca..f06cfe28ea5d295b8b78c64910c93418e926bcec 100644 --- a/applications/utilities/mesh/manipulation/splitMesh/regionSide.C +++ b/applications/utilities/mesh/manipulation/splitMesh/regionSide.C @@ -301,10 +301,7 @@ void Foam::regionSide::walkAllPointConnectedFaces const label facei = iter.key(); const labelList& fEdges = mesh.faceEdges()[facei]; - forAll(fEdges, fEdgeI) - { - regionEdges.insert(fEdges[fEdgeI]); - } + regionEdges.insertMany(fEdges); } diff --git a/applications/utilities/parallelProcessing/decomposePar/decomposePar.C b/applications/utilities/parallelProcessing/decomposePar/decomposePar.C index 0ac8b9af1b9f92af5c9837db8c25ddd095d30095..fa0dd946bd53bc6d6878b4298b9806354cb3dfdc 100644 --- a/applications/utilities/parallelProcessing/decomposePar/decomposePar.C +++ b/applications/utilities/parallelProcessing/decomposePar/decomposePar.C @@ -311,7 +311,7 @@ int main(int argc, char *argv[]) wordHashSet names; forAllConstIters(rp, iter) { - names.insert(iter.object()); + names.insertMany(iter.object()); } regionNames = names.sortedToc(); diff --git a/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C b/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C index cdd092b12764bdd81d5c2c3528c18eeeb8f7e762..c8ab33cfa24ad2ae0151680620fff9d549e644fb 100644 --- a/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C +++ b/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C @@ -186,7 +186,7 @@ int main(int argc, char *argv[]) wordHashSet names; forAllConstIters(rp, iter) { - names.insert(iter.object()); + names.insertMany(iter.object()); } regionNames = names.sortedToc(); diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/findFields.H b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/findFields.H index 1172760228e01d2f27167458be94e7b8f4440e34..1a98fcd52e84d745b670efa557e003e83f0935e7 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/findFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/findFields.H @@ -103,9 +103,9 @@ if (timeDirs.size()) fileName::FILE ); - forAll(contents, fileI) + for (const fileName& file : contents) { - missing.erase(contents[fileI].name()); + missing.erase(file.name()); } volumeFields.erase(missing); diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamUpdateInfo.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamUpdateInfo.C index 290f4ad41be85d59e820f8aa9e24f21dd438da52..391bf077821598bdd9c1f56933ee99e4b656159b 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamUpdateInfo.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamUpdateInfo.C @@ -227,7 +227,7 @@ void Foam::vtkPVFoam::updateInfoLagrangian for (const instant& t : dbPtr_().times()) { - names.insert + names.insertMany ( readDir ( diff --git a/applications/utilities/preProcessing/createZeroDirectory/boundaryInfo.C b/applications/utilities/preProcessing/createZeroDirectory/boundaryInfo.C index a44a9066642ed6d93d1009f105eb02dda63111f3..16671a4ec2b2500ca86509947a52566602b96eb2 100644 --- a/applications/utilities/preProcessing/createZeroDirectory/boundaryInfo.C +++ b/applications/utilities/preProcessing/createZeroDirectory/boundaryInfo.C @@ -123,7 +123,7 @@ Foam::boundaryInfo::boundaryInfo(const Time& runTime, const word& regionName) if (dict.found("inGroups")) { dict.lookup("inGroups") >> groups_[patchI]; - allGroupNames_.insert(groups_[patchI]); + allGroupNames_.insertMany(groups_[patchI]); } } } diff --git a/applications/utilities/surface/surfaceCheck/surfaceCheck.C b/applications/utilities/surface/surfaceCheck/surfaceCheck.C index 1fc36e78cce681ded5261cf88cf8845f96145f37..1b76d0a8add02006eee7eb9b2adafbd6a01ed8c5 100644 --- a/applications/utilities/surface/surfaceCheck/surfaceCheck.C +++ b/applications/utilities/surface/surfaceCheck/surfaceCheck.C @@ -225,9 +225,9 @@ void syncEdges(const triSurface& p, labelHashSet& markedEdges) const edgeList& edges = p.edges(); edgeHashSet edgeSet(2*markedEdges.size()); - forAllConstIter(labelHashSet, markedEdges, iter) + for (const label edgei : markedEdges) { - edgeSet.insert(edges[iter.key()]); + edgeSet.insert(edges[edgei]); } forAll(edges, edgei) diff --git a/applications/utilities/surface/surfaceMeshTriangulate/surfaceMeshTriangulate.C b/applications/utilities/surface/surfaceMeshTriangulate/surfaceMeshTriangulate.C index 86f35516b15b4c94f96a24dfaf938fcffd1f5acc..b5b2421b609ea16b9d0df746f86c1812d6b2f0e4 100644 --- a/applications/utilities/surface/surfaceMeshTriangulate/surfaceMeshTriangulate.C +++ b/applications/utilities/surface/surfaceMeshTriangulate/surfaceMeshTriangulate.C @@ -202,11 +202,7 @@ int main(int argc, char *argv[]) for (const wordRe& zoneName : zoneNames) { labelList zoneIDs = findStrings(zoneName, allZoneNames); - - forAll(zoneIDs, j) - { - includeFaceZones.insert(zoneIDs[j]); - } + includeFaceZones.insertMany(zoneIDs); if (zoneIDs.empty()) { diff --git a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.C b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.C index 9fc7370d103a7f292d288726f5312ecedc926002..90dcbea5ebbd2d4ed20f7cb0e75b3fd8ec334824 100644 --- a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.C +++ b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -33,55 +33,36 @@ License template<class Key, class Hash> template<class InputIter> -inline Foam::label Foam::HashSet<Key, Hash>::insertMultiple +inline Foam::label Foam::HashSet<Key, Hash>::assignMany ( - const InputIter begIter, - const InputIter endIter -) -{ - label changed = 0; - for (InputIter iter = begIter; iter != endIter; ++iter) - { - if (insert(*iter)) - { - ++changed; - } - } - return changed; -} - - -template<class Key, class Hash> -template<class InputIter> -inline Foam::label Foam::HashSet<Key, Hash>::assignMultiple -( - const InputIter begIter, - const InputIter endIter, - const label sz + const label nItems, + InputIter first, + InputIter last ) { if (!this->capacity()) { // Could be zero-sized from a previous transfer()? - this->resize(sz); + this->resize(2*nItems); } else { this->clear(); } - return insertMultiple(begIter, endIter); + return insert(first, last); } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template<class Key, class Hash> -Foam::HashSet<Key, Hash>::HashSet(const UList<Key>& lst) +template<unsigned Size> +Foam::HashSet<Key, Hash>::HashSet(const FixedList<Key, Size>& list) : - parent_type(2*lst.size()) + parent_type(2*list.size()) { - for (const auto& k : lst) + for (const auto& k : list) { this->insert(k); } @@ -89,12 +70,11 @@ Foam::HashSet<Key, Hash>::HashSet(const UList<Key>& lst) template<class Key, class Hash> -template<unsigned Size> -Foam::HashSet<Key, Hash>::HashSet(const FixedList<Key, Size>& lst) +Foam::HashSet<Key, Hash>::HashSet(const UList<Key>& list) : - parent_type(2*lst.size()) + parent_type(2*list.size()) { - for (const auto& k : lst) + for (const auto& k : list) { this->insert(k); } @@ -102,11 +82,23 @@ Foam::HashSet<Key, Hash>::HashSet(const FixedList<Key, Size>& lst) template<class Key, class Hash> -Foam::HashSet<Key, Hash>::HashSet(std::initializer_list<Key> lst) +Foam::HashSet<Key, Hash>::HashSet(const UIndirectList<Key>& list) : - parent_type(2*lst.size()) + parent_type(2*list.size()) { - for (const auto& k : lst) + for (const auto& k : list) + { + this->insert(k); + } +} + + +template<class Key, class Hash> +Foam::HashSet<Key, Hash>::HashSet(std::initializer_list<Key> list) +: + parent_type(2*list.size()) +{ + for (const auto& k : list) { this->insert(k); } @@ -132,24 +124,116 @@ Foam::HashSet<Key, Hash>::HashSet // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template<class Key, class Hash> -Foam::label Foam::HashSet<Key, Hash>::insert(const UList<Key>& lst) +template<class InputIter> +inline Foam::label Foam::HashSet<Key, Hash>::insert +( + InputIter first, + InputIter last +) +{ + label changed = 0; + for (; first != last; ++first) + { + if (insert(*first)) + { + ++changed; + } + } + return changed; +} + + +template<class Key, class Hash> +inline Foam::label Foam::HashSet<Key, Hash>::insert +( + std::initializer_list<Key> list +) { - return insertMultiple(lst.begin(), lst.end()); + return insert(list.begin(), list.end()); } template<class Key, class Hash> template<unsigned Size> -Foam::label Foam::HashSet<Key, Hash>::insert(const FixedList<Key, Size>& lst) +inline Foam::label Foam::HashSet<Key, Hash>::insertMany +( + const FixedList<Key, Size>& list +) { - return insertMultiple(lst.begin(), lst.end()); + return insert(list.begin(), list.end()); } template<class Key, class Hash> -Foam::label Foam::HashSet<Key, Hash>::insert(std::initializer_list<Key> lst) +inline Foam::label Foam::HashSet<Key, Hash>::insertMany +( + const UList<Key>& list +) { - return insertMultiple(lst.begin(), lst.end()); + return insert(list.begin(), list.end()); +} + + +template<class Key, class Hash> +inline Foam::label Foam::HashSet<Key, Hash>::insertMany +( + const UIndirectList<Key>& list +) +{ + return insert(list.begin(), list.end()); +} + + +template<class Key, class Hash> +template<class InputIter> +inline Foam::label Foam::HashSet<Key, Hash>::unset +( + InputIter first, + InputIter last +) +{ + return this->parent_type::erase(first, last); +} + + +template<class Key, class Hash> +inline Foam::label Foam::HashSet<Key, Hash>::unset +( + std::initializer_list<Key> list +) +{ + return unset(list.begin(), list.end()); +} + + +template<class Key, class Hash> +template<unsigned Size> +inline Foam::label Foam::HashSet<Key, Hash>::unsetMany +( + const FixedList<Key, Size>& list +) +{ + return unset(list.begin(), list.end()); +} + + +template<class Key, class Hash> +inline Foam::label Foam::HashSet<Key, Hash>::unsetMany +( + const UList<Key>& list +) +{ + return unset(list.begin(), list.end()); +} + + +template<class Key, class Hash> +inline Foam::label Foam::HashSet<Key, Hash>::unsetMany +( + const UIndirectList<Key>& list +) +{ + return unset(list.begin(), list.end()); } @@ -170,24 +254,24 @@ inline bool Foam::HashSet<Key, Hash>::operator[](const Key& key) const template<class Key, class Hash> -void Foam::HashSet<Key, Hash>::operator=(const UList<Key>& rhs) +template<unsigned Size> +void Foam::HashSet<Key, Hash>::operator=(const FixedList<Key, Size>& rhs) { - assignMultiple(rhs.begin(), rhs.end(), 2*rhs.size()); + assignMany(rhs.size(), rhs.begin(), rhs.end()); } template<class Key, class Hash> -template<unsigned Size> -void Foam::HashSet<Key, Hash>::operator=(const FixedList<Key, Size>& rhs) +void Foam::HashSet<Key, Hash>::operator=(const UList<Key>& rhs) { - assignMultiple(rhs.begin(), rhs.end(), 2*rhs.size()); + assignMany(rhs.size(), rhs.begin(), rhs.end()); } template<class Key, class Hash> void Foam::HashSet<Key, Hash>::operator=(std::initializer_list<Key> rhs) { - assignMultiple(rhs.begin(), rhs.end(), 2*rhs.size()); + assignMany(rhs.size(), rhs.begin(), rhs.end()); } diff --git a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H index da024138b6d5294e655d188c4ad68f00282f8f7c..343e4986d955ae0e13c58c6f01388574af17329b 100644 --- a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H +++ b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H @@ -63,6 +63,7 @@ Description #define HashSet_H #include "HashTable.H" +#include "UIndirectList.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -87,21 +88,13 @@ class HashSet { // Private Member Functions - //- Insert values, using begin/end iterators. + //- Assign from the input iterator range template<class InputIter> - inline label insertMultiple + inline label assignMany ( - const InputIter begIter, - const InputIter endIter - ); - - //- Assign using begin/end iterators. - template<class InputIter> - inline label assignMultiple - ( - const InputIter begIter, - const InputIter endIter, - const label sz + const label nItems, + InputIter first, + InputIter last ); @@ -140,15 +133,18 @@ public: parent_type(is) {} - //- Construct from UList of Key - explicit HashSet(const UList<Key>& lst); - //- Construct from FixedList of Key template<unsigned Size> - explicit HashSet(const FixedList<Key, Size>& lst); + explicit HashSet(const FixedList<Key, Size>& list); + + //- Construct from UList of Key + explicit HashSet(const UList<Key>& list); + + //- Construct from an indirect list + explicit HashSet(const UIndirectList<Key>& list); //- Construct from an initializer list of Key - HashSet(std::initializer_list<Key> lst); + HashSet(std::initializer_list<Key> list); //- Copy construct HashSet(const this_type& hs) @@ -180,96 +176,97 @@ public: return this->parent_type::insert(key, zero::null()); } - //- Insert keys from the list of Key + //- Same as insert (no value to overwrite) + bool set(const Key& key) + { + return insert(key); + } + + //- Unset the specified key - same as erase + // \return True if the entry existed and was removed + bool unset(const Key& key) + { + return this->parent_type::erase(key); + } + + + // Convenience + + //- Insert keys from the input iterator range // \return The number of new elements inserted - label insert(const UList<Key>& lst); + template<class InputIter> + inline label insert(InputIter first, InputIter last); + + //- Insert keys from a initializer list of Key + // \return The number of new elements inserted + inline label insert(std::initializer_list<Key> list); //- Insert keys from the list of Key // \return The number of new elements inserted template<unsigned Size> - label insert(const FixedList<Key, Size>& lst); + inline label insertMany(const FixedList<Key, Size>& list); - //- Insert keys from a initializer list of Key + //- Insert keys from the list of Key // \return The number of new elements inserted - label insert(std::initializer_list<Key> lst); + inline label insertMany(const UList<Key>& list); + + //- Insert keys from the list of Key + // \return The number of new elements inserted + inline label insertMany(const UIndirectList<Key>& list); //- Same as insert (no value to overwrite) - bool set(const Key& key) + template<class InputIter> + inline label set(InputIter first, InputIter last) { - return insert(key); + return insert(first, last); } //- Same as insert (no value to overwrite) - label set(const UList<Key>& lst) + inline label set(std::initializer_list<Key> list) { - return insert(lst); + return insert(list); } //- Same as insert (no value to overwrite) template<unsigned Size> - label set(const FixedList<Key, Size>& lst) + inline label setMany(const FixedList<Key, Size>& list) { - return insert(lst); + return insertMany(list); } - //- Same as insert (no value to overwrite) - label set(std::initializer_list<Key> lst) + //- Same as insertMany (no value to overwrite) + inline label setMany(const UList<Key>& list) { - return insert(lst); + return insertMany(list); } - //- Unset the specified key - same as erase - // \return True if the entry existed and was removed - bool unset(const Key& key) + //- Same as insertMany (no value to overwrite) + inline label setMany(const UIndirectList<Key>& list) { - return this->parent_type::erase(key); + return insertMany(list); } + //- Unset the keys listed in the input iterator range + // \return The number of items removed + template<class InputIter> + inline label unset(InputIter first, const InputIter last); + //- Unset the listed keys - same as erase // \return The number of items removed - label unset(const UList<Key>& lst) - { - return this->parent_type::erase(lst); - } + inline label unset(std::initializer_list<Key> list); //- Unset the listed keys - same as erase // \return The number of items removed template<unsigned Size> - label unset(const FixedList<Key, Size>& lst) - { - return this->parent_type::erase(lst); - } + inline label unsetMany(const FixedList<Key, Size>& list); //- Unset the listed keys - same as erase // \return The number of items removed - label unset(std::initializer_list<Key> lst) - { - return this->parent_type::erase(lst); - } + inline label unsetMany(const UList<Key>& list); - //- Not applicable for HashSet - template<class UnaryPredicate> - List<Key> tocValues(const UnaryPredicate&, const bool) = delete; - - //- Not applicable for HashSet - template<class BinaryPredicate> - List<Key> tocEntries(const BinaryPredicate&, const bool) = delete; - - //- Not applicable for HashSet - template<class UnaryPredicate> - label countValues(const UnaryPredicate&, const bool) = delete; - - //- Not applicable for HashSet - template<class BinaryPredicate> - label countEntries(const BinaryPredicate&, const bool) = delete; - - //- Not applicable for HashSet - template<class UnaryPredicate> - label filterValues(const UnaryPredicate&, const bool) = delete; - - //- Not applicable for HashSet - template<class BinaryPredicate> - label filterEntries(const BinaryPredicate&, const bool) = delete; + //- Unset the listed keys - same as erase + // \return The number of items removed + inline label unsetMany(const UIndirectList<Key>& list); // STL iterators @@ -330,7 +327,7 @@ public: // Assignment //- Assignment from a UList of keys - void operator=(const UList<Key>& lst); + void operator=(const UList<Key>& rhs); //- Assignment from a FixedList of keys template<unsigned Size> @@ -369,6 +366,33 @@ public: const HashSet<Key, Hash>& tbl ); + + // Housekeeping + + //- Not applicable for HashSet + template<class UnaryPredicate> + List<Key> tocValues(const UnaryPredicate&, const bool) = delete; + + //- Not applicable for HashSet + template<class BinaryPredicate> + List<Key> tocEntries(const BinaryPredicate&, const bool) = delete; + + //- Not applicable for HashSet + template<class UnaryPredicate> + label countValues(const UnaryPredicate&, const bool) = delete; + + //- Not applicable for HashSet + template<class BinaryPredicate> + label countEntries(const BinaryPredicate&, const bool) = delete; + + //- Not applicable for HashSet + template<class UnaryPredicate> + label filterValues(const UnaryPredicate&, const bool) = delete; + + //- Not applicable for HashSet + template<class BinaryPredicate> + label filterEntries(const BinaryPredicate&, const bool) = delete; + }; diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C index e96d1311e95fca2c5f7c2d3ee5661260593dfb1e..b57be56135f2906d55c08c6f8e576724bf8e3ec7 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C @@ -30,35 +30,6 @@ License #include "List.H" #include "FixedList.H" -// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // - -template<class T, class Key, class Hash> -template<class InputIter> -Foam::label Foam::HashTable<T, Key, Hash>::eraseMultiple -( - const InputIter begIter, - const InputIter endIter -) -{ - const label nTotal = this->size(); - label changed = 0; - - for - ( - InputIter iter = begIter; - changed < nTotal && iter != endIter; // terminate early - ++iter - ) - { - if (this->erase(*iter)) - { - ++changed; - } - } - return changed; -} - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template<class T, class Key, class Hash> @@ -435,30 +406,60 @@ bool Foam::HashTable<T, Key, Hash>::erase(const Key& key) template<class T, class Key, class Hash> -Foam::label Foam::HashTable<T, Key, Hash>::erase(const UList<Key>& keys) +template<class InputIter> +inline Foam::label Foam::HashTable<T, Key, Hash>::erase +( + InputIter first, + InputIter last +) { - return eraseMultiple(keys.cbegin(), keys.cend()); + label changed = 0; + + for + ( + const label nTotal = this->size(); + changed < nTotal && first != last; // terminate early + ++first + ) + { + if (this->erase(*first)) + { + ++changed; + } + } + + return changed; +} + + +template<class T, class Key, class Hash> +inline Foam::label Foam::HashTable<T, Key, Hash>::erase +( + std::initializer_list<Key> keys +) +{ + return erase(keys.begin(), keys.end()); } template<class T, class Key, class Hash> template<unsigned Size> -Foam::label Foam::HashTable<T, Key, Hash>::erase +inline Foam::label Foam::HashTable<T, Key, Hash>::eraseMany ( const FixedList<Key, Size>& keys ) { - return eraseMultiple(keys.cbegin(), keys.cend()); + return erase(keys.cbegin(), keys.cend()); } template<class T, class Key, class Hash> -Foam::label Foam::HashTable<T, Key, Hash>::erase +inline Foam::label Foam::HashTable<T, Key, Hash>::eraseMany ( - std::initializer_list<Key> keys + const UList<Key>& keys ) { - return eraseMultiple(keys.begin(), keys.end()); + return erase(keys.cbegin(), keys.cend()); } diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H index 922fe917cedb43db58a825e7a7bbe6929695079b..6d67ba326498cf1830bf2a22e1dbbb759a2fa462 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H @@ -311,18 +311,6 @@ protected: //- An iterator with non-const access to HashTable internals. friend class Iterator<false>; - - // Protected Member Functions - - //- Remove using begin/end iterators of listed keys - template<class InputIter> - inline label eraseMultiple - ( - const InputIter begIter, - const InputIter endIter - ); - - public: // Constructors @@ -352,7 +340,7 @@ public: // Member Functions - // Access + // Access //- The size of the underlying table inline label capacity() const; @@ -382,7 +370,7 @@ public: inline const T& lookup(const Key& key, const T& deflt) const; - // Table of contents + // Table of contents //- The table of contents (the keys) in unsorted order. List<Key> toc() const; @@ -465,7 +453,7 @@ public: ) const; - // Edit + // Edit //- Insert a new entry, not overwriting existing entries. // \return True if the entry inserted, which means that it did @@ -495,27 +483,31 @@ public: // \return True if the entry existed and was removed bool erase(const Key& key); - //- Remove table entries given by the listed keys + //- Remove table entries given by keys of the other hash-table. + // + // The other hash-table must have the same type of key, but the + // type of values held and the hashing function are arbitrary. + // // \return The number of items removed - label erase(const UList<Key>& keys); + template<class AnyType, class AnyHash> + label erase(const HashTable<AnyType, Key, AnyHash>& other); //- Remove table entries given by the listed keys // \return The number of items removed - template<unsigned Size> - label erase(const FixedList<Key, Size>& keys); + inline label erase(std::initializer_list<Key> keys); + + //- Remove multiple entries using an iterator range of keys + template<class InputIter> + inline label erase(InputIter first, InputIter last); //- Remove table entries given by the listed keys // \return The number of items removed - label erase(std::initializer_list<Key> keys); + template<unsigned Size> + inline label eraseMany(const FixedList<Key, Size>& keys); - //- Remove table entries given by keys of the other hash-table. - // - // The other hash-table must have the same type of key, but the - // type of values held and the hashing function are arbitrary. - // + //- Remove table entries given by the listed keys // \return The number of items removed - template<class AnyType, class AnyHash> - label erase(const HashTable<AnyType, Key, AnyHash>& other); + inline label eraseMany(const UList<Key>& keys); //- Retain table entries given by keys of the other hash-table. // diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C index 76ee09ff27f1192209658edb48cb36e0b1ce78ae..86a07145d014d6052d2d83d1c26e7a0173d06964 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C @@ -305,7 +305,7 @@ bool Foam::functionObjectList::readFunctionObject else if (args.size() > 1) { funcDict.set("fields", args); - requiredFields.insert(args); + requiredFields.insertMany(args); } else if (funcDict.found("field")) { @@ -313,7 +313,7 @@ bool Foam::functionObjectList::readFunctionObject } else if (funcDict.found("fields")) { - requiredFields.insert(wordReList(funcDict.lookup("fields"))); + requiredFields.insertMany(wordReList(funcDict.lookup("fields"))); } // Insert named arguments diff --git a/src/OpenFOAM/meshes/meshShapes/edge/edge.H b/src/OpenFOAM/meshes/meshShapes/edge/edge.H index 7cff69f33e13a126223a4d139b5472ea4dbd3503..83e2b5ea3031f63b0e7c152716d4fc49ba067c4c 100644 --- a/src/OpenFOAM/meshes/meshShapes/edge/edge.H +++ b/src/OpenFOAM/meshes/meshShapes/edge/edge.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -62,25 +62,6 @@ class edge : public labelPair { - // Private Member Functions - - //- Insert values, using begin/end iterators. - template<class InputIter> - inline label insertMultiple - ( - const InputIter begIter, - const InputIter endIter - ); - - //- Remove values, using begin/end iterators. - template<class InputIter> - inline label eraseMultiple - ( - const InputIter begIter, - const InputIter endIter - ); - - public: // Static data members @@ -100,13 +81,13 @@ public: inline edge(const labelPair& pair); //- Construct from list - inline edge(const FixedList<label, 2>& lst); + inline edge(const FixedList<label, 2>& list); //- Construct from two point labels, sorted with first less-than second inline edge(const label from, const label to, const bool doSort); //- Construct from list, sorted with first less-than second - inline edge(const FixedList<label, 2>& lst, const bool doSort); + inline edge(const FixedList<label, 2>& list, const bool doSort); //- Construct from Istream inline edge(Istream& is); @@ -194,6 +175,7 @@ public: //- 'Clears' edge by setting both ends to invalid point labels. inline void clear(); + //- Fill any open slot with the index if it did not previously exist. // Returns true on success. A negative label never inserts. // Similar to a HashTable::insert(). @@ -203,20 +185,25 @@ public: // Returns true on success. Negative labels never insert. // Return the number of slots filled. // Similar to a HashTable::insert(). - inline label insert(const labelUList& lst); + inline label insert(std::initializer_list<label> list); + + //- Insert values, using begin/end iterators. + template<class InputIter> + inline label insert(InputIter begIter, InputIter endIter); //- Fill open slots with the indices if they did not previously exist. // Returns true on success. Negative labels never insert. // Return the number of slots filled. - // Similar to a HashTable::insert(). + // Similar to a HashTable::insertMany(). template<unsigned Size> - inline label insert(const FixedList<label, Size>& lst); + inline label insertMany(const FixedList<label, Size>& list); //- Fill open slots with the indices if they did not previously exist. // Returns true on success. Negative labels never insert. // Return the number of slots filled. - // Similar to a HashTable::insert(). - inline label insert(std::initializer_list<label> lst); + // Similar to a HashTable::insertMany(). + inline label insertMany(const labelUList& list); + //- Remove an existing index from the edge and set its location to '-1'. // Returns the number of changes. A negative label never removes. @@ -225,19 +212,23 @@ public: //- Remove existing indices from the edge and set locations to '-1'. // Returns the number of changes. - inline label erase(const labelUList& lst); + inline label erase(std::initializer_list<label> list); + + //- Remove values, using begin/end iterators. + template<class InputIter> + inline label erase(InputIter begIter, InputIter endIter); //- Remove existing indices from the edge and set locations to '-1'. // Returns the number of changes. template<unsigned Size> - inline label erase(const FixedList<label, Size>& lst); + inline label eraseMany(const FixedList<label, Size>& list); //- Remove existing indices from the edge and set locations to '-1'. // Returns the number of changes. - inline label erase(std::initializer_list<label> lst); + inline label eraseMany(const labelUList& list); - // Geometric functions + // Geometric functions //- Return centre point (centroid) of the edge. // No special handling of negative point labels. @@ -260,7 +251,7 @@ public: inline linePointRef line(const UList<point>& pts) const; - // Comparison + // Comparison //- Compare edges // \return diff --git a/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H b/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H index 4957bd1336d0e32603a5f5a7a53a3031658108f7..fcdaadc7167cb6a9aa090b45710e5989be709e44 100644 --- a/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H +++ b/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -33,66 +33,6 @@ inline int Foam::edge::compare(const edge& a, const edge& b) } -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -template<class InputIter> -inline Foam::label Foam::edge::insertMultiple -( - const InputIter begIter, - const InputIter endIter -) -{ - // Available slots. - // Don't use count() since it has special treatment for duplicates - const int maxChange = (first() < 0 ? 1 : 0) + (second() < 0 ? 1 : 0); - - int changed = 0; - if (maxChange) - { - for (InputIter iter = begIter; iter != endIter; ++iter) - { - if (insert(*iter)) - { - if (++changed >= maxChange) - { - break; - } - } - } - } - - return changed; -} - - -template<class InputIter> -inline Foam::label Foam::edge::eraseMultiple -( - const InputIter begIter, - const InputIter endIter -) -{ - // Occupied slots. - // Don't use count() since it has special treatment for duplicates - const int maxChange = (first() >= 0 ? 1 : 0) + (second() >= 0 ? 1 : 0); - - int changed = 0; - if (maxChange) - { - for (InputIter iter = begIter; iter != endIter; ++iter) - { - changed += erase(*iter); - if (changed >= maxChange) - { - break; - } - } - } - - return changed; -} - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // inline Foam::edge::edge() @@ -113,9 +53,9 @@ inline Foam::edge::edge(const labelPair& pair) {} -inline Foam::edge::edge(const FixedList<label, 2>& lst) +inline Foam::edge::edge(const FixedList<label, 2>& list) : - labelPair(lst.first(), lst.last()) + labelPair(list.first(), list.last()) {} @@ -125,9 +65,9 @@ inline Foam::edge::edge(const label from, const label to, const bool doSort) {} -inline Foam::edge::edge(const FixedList<label, 2>& lst, const bool doSort) +inline Foam::edge::edge(const FixedList<label, 2>& list, const bool doSort) : - labelPair(lst, doSort) + labelPair(list, doSort) {} @@ -329,22 +269,46 @@ inline bool Foam::edge::insert(const label index) } -inline Foam::label Foam::edge::insert(const labelUList& lst) +template<class InputIter> +inline Foam::label Foam::edge::insert +( + InputIter begIter, + InputIter endIter +) { - return insertMultiple(lst.begin(), lst.end()); + // Available slots. + // Don't use count() since it has special treatment for duplicates + const int maxChange = ((first() < 0 ? 1 : 0) + (second() < 0 ? 1 : 0)); + + int changed = 0; + for (; changed < maxChange && begIter != endIter; ++begIter) + { + if (insert(*begIter)) + { + ++changed; + } + } + + return changed; +} + + +inline Foam::label Foam::edge::insert(std::initializer_list<label> list) +{ + return insert(list.begin(), list.end()); } template<unsigned Size> -inline Foam::label Foam::edge::insert(const FixedList<label, Size>& lst) +inline Foam::label Foam::edge::insertMany(const FixedList<label, Size>& list) { - return insertMultiple(lst.begin(), lst.end()); + return insert(list.begin(), list.end()); } -inline Foam::label Foam::edge::insert(std::initializer_list<label> lst) +inline Foam::label Foam::edge::insertMany(const labelUList& list) { - return insertMultiple(lst.begin(), lst.end()); + return insert(list.begin(), list.end()); } @@ -374,22 +338,43 @@ inline Foam::label Foam::edge::erase(const label index) } -inline Foam::label Foam::edge::erase(const labelUList& lst) +template<class InputIter> +inline Foam::label Foam::edge::erase +( + InputIter begIter, + InputIter endIter +) +{ + // Occupied slots. + // Don't use count() since it has special treatment for duplicates + const int maxChange = ((first() >= 0 ? 1 : 0) + (second() >= 0 ? 1 : 0)); + + int changed = 0; + for (; changed < maxChange && begIter != endIter; ++begIter) + { + changed += erase(*begIter); + } + + return changed; +} + + +inline Foam::label Foam::edge::erase(std::initializer_list<label> list) { - return eraseMultiple(lst.begin(), lst.end()); + return erase(list.begin(), list.end()); } template<unsigned Size> -inline Foam::label Foam::edge::erase(const FixedList<label, Size>& lst) +inline Foam::label Foam::edge::eraseMany(const FixedList<label, Size>& list) { - return eraseMultiple(lst.begin(), lst.end()); + return erase(list.begin(), list.end()); } -inline Foam::label Foam::edge::erase(std::initializer_list<label> lst) +inline Foam::label Foam::edge::eraseMany(const labelUList& list) { - return eraseMultiple(lst.begin(), lst.end()); + return erase(list.begin(), list.end()); } diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C index 3f75be93e5d15f36862d402314107ab2f9b5d0c9..745fcb4958487f989eea59e81346d5c5ef8dfe80 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C @@ -784,11 +784,7 @@ Foam::labelHashSet Foam::polyBoundaryMesh::patchSet // Treat the given patch names as wild-cards and search the set // of all patch names for matches labelList patchIDs = findStrings(patchName, allPatchNames); - - forAll(patchIDs, j) - { - ids.insert(patchIDs[j]); - } + ids.insertMany(patchIDs); if (patchIDs.empty()) { @@ -803,11 +799,7 @@ Foam::labelHashSet Foam::polyBoundaryMesh::patchSet { const word& name = allGroupNames[groupIDs[i]]; const labelList& extraPatchIDs = groupPatchIDs()[name]; - - forAll(extraPatchIDs, extraI) - { - ids.insert(extraPatchIDs[extraI]); - } + ids.insertMany(extraPatchIDs); } if (groupIDs.empty() && warnNotFound) diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCellPoints.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCellPoints.C index 0f96e519ccae60ebd73040d7d6f9e4fccdc7fdb3..ab96883fbfde4332eddf4d70381e259cfadc2ad5 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCellPoints.C +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCellPoints.C @@ -75,7 +75,7 @@ const Foam::labelList& Foam::primitiveMesh::cellPoints for (const label facei : cFaces) { - set.insert(fcs[facei]); + set.insertMany(fcs[facei]); } storage.clear(); diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshEdges.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshEdges.C index cc91132dc6783a0a14b7826f1e286da5f37760ed..4e46d6294d06e965f8fd938d324e8b0b6fcac090 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshEdges.C +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshEdges.C @@ -646,7 +646,7 @@ const Foam::labelList& Foam::primitiveMesh::cellEdges for (const label facei : cFaces) { - set.insert(faceEdges(facei)); + set.insertMany(faceEdges(facei)); } storage.clear(); diff --git a/src/conversion/vtk/part/foamVtuSizing.C b/src/conversion/vtk/part/foamVtuSizing.C index 07752d63dfef202000c85354c56cb21da6defac7..0bb9fb5592ddbdd10650135427dddf73eb4126b8 100644 --- a/src/conversion/vtk/part/foamVtuSizing.C +++ b/src/conversion/vtk/part/foamVtuSizing.C @@ -124,9 +124,9 @@ void Foam::vtk::vtuSizing::reset bool first = true; const cell& cFaces = mesh.cells()[celli]; - forAll(cFaces, cFaceI) + for (const label facei : cFaces) { - const face& f = mesh.faces()[cFaces[cFaceI]]; + const face& f = mesh.faces()[facei]; // Face decomposed into triangles and quads // Tri -> Tet, Quad -> Pyr @@ -160,12 +160,12 @@ void Foam::vtk::vtuSizing::reset // number of faces, size of each face, vertices per face // [nFaces, nFace0Pts, id1, id2, ..., nFace1Pts, id1, id2, ...] - forAll(cFaces, cFaceI) + for (const label facei : cFaces) { - const face& f = mesh.faces()[cFaces[cFaceI]]; + const face& f = mesh.faces()[facei]; nFaceLabels_ += f.size(); - hashUniqId.insert(f); + hashUniqId.insertMany(f); } // Legacy format only uses the face-stream. diff --git a/src/conversion/vtk/part/foamVtuSizingTemplates.C b/src/conversion/vtk/part/foamVtuSizingTemplates.C index 76133d03a35293265edfa59480143f9d073886fc..4bfda81ac636f81ef536340979c8e2cb7407429e 100644 --- a/src/conversion/vtk/part/foamVtuSizingTemplates.C +++ b/src/conversion/vtk/part/foamVtuSizingTemplates.C @@ -545,10 +545,7 @@ void Foam::vtk::vtuSizing::populateArrays const face& f = mesh.faces()[cFaces[cFaceI]]; const bool isOwner = (owner[cFaces[cFaceI]] == celli); - forAll(f, fp) - { - hashUniqId.insert(f[fp]); - } + hashUniqId.insertMany(f); // number of labels for this face faceOutput[faceIndexer++] = f.size(); diff --git a/src/dynamicMesh/attachDetach/detachInterface.C b/src/dynamicMesh/attachDetach/detachInterface.C index 76ced713a048b53538f42ac4abbf2e79ff4754ba..f00979846a00bee367f7784646859de7b2c00e77 100644 --- a/src/dynamicMesh/attachDetach/detachInterface.C +++ b/src/dynamicMesh/attachDetach/detachInterface.C @@ -329,11 +329,7 @@ void Foam::attachDetach::detachInterface { // Protection and memory management // Make a map of master cells for quick reject labelHashSet mcMap(2*mc.size()); - - forAll(mc, mcI) - { - mcMap.insert(mc[mcI]); - } + mcMap.insertMany(mc); // Go through all the faces in the masterCellFaceMap. If the // cells around them are not already used, add all of their @@ -349,11 +345,7 @@ void Foam::attachDetach::detachInterface { // Cell not found. Add its faces to the map const cell& curFaces = cells[ownCell]; - - forAll(curFaces, facei) - { - masterCellFaceMap.insert(curFaces[facei]); - } + masterCellFaceMap.insertMany(curFaces); } // Do the neighbour side if face is internal @@ -365,11 +357,7 @@ void Foam::attachDetach::detachInterface { // Cell not found. Add its faces to the map const cell& curFaces = cells[neiCell]; - - forAll(curFaces, facei) - { - masterCellFaceMap.insert(curFaces[facei]); - } + masterCellFaceMap.insertMany(curFaces); } } } diff --git a/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C b/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C index 5a3b9b649c55bbab5eb9422a8ccd04eb2a0a7ae0..36df8b2dd3adb1c0282753f73485f7107baf423c 100644 --- a/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C +++ b/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C @@ -228,10 +228,7 @@ Foam::wordList Foam::fvMeshDistribute::mergeWordList(const wordList& procNames) wordHashSet mergedNames; forAll(allNames, proci) { - forAll(allNames[proci], i) - { - mergedNames.insert(allNames[proci][i]); - } + mergedNames.insertMany(allNames[proci]); } return mergedNames.toc(); } diff --git a/src/dynamicMesh/motionSmoother/motionSmootherAlgo.C b/src/dynamicMesh/motionSmoother/motionSmootherAlgo.C index ba31bb9b0abeeb0c5412d1c543d01ae14a06bda3..9d2e584ef5f8dd54d60616c6d57722d838b86cf0 100644 --- a/src/dynamicMesh/motionSmoother/motionSmootherAlgo.C +++ b/src/dynamicMesh/motionSmoother/motionSmootherAlgo.C @@ -99,7 +99,7 @@ Foam::labelHashSet Foam::motionSmootherAlgo::getPoints for (const label faceId : faceLabels) { - usedPoints.insert(mesh_.faces()[faceId]); + usedPoints.insertMany(mesh_.faces()[faceId]); } return usedPoints; @@ -115,7 +115,7 @@ Foam::labelHashSet Foam::motionSmootherAlgo::getPoints for (const label faceId : faceLabels) { - usedPoints.insert(mesh_.faces()[faceId]); + usedPoints.insertMany(mesh_.faces()[faceId]); } return usedPoints; @@ -217,11 +217,11 @@ void Foam::motionSmootherAlgo::scaleField pointScalarField& fld ) const { - forAllConstIter(labelHashSet, pointLabels, iter) + for (const label pointi : pointLabels) { - if (isInternalPoint(iter.key())) + if (isInternalPoint(pointi)) { - fld[iter.key()] *= scale; + fld[pointi] *= scale; } } @@ -239,10 +239,8 @@ void Foam::motionSmootherAlgo::scaleField pointScalarField& fld ) const { - forAll(meshPoints, i) + for (const label pointi : meshPoints) { - label pointi = meshPoints[i]; - if (pointLabels.found(pointi)) { fld[pointi] *= scale; @@ -330,10 +328,7 @@ void Foam::motionSmootherAlgo::getAffectedFacesAndPoints { const cell& cFaces = mesh_.cells()[pCells[pCelli]]; - forAll(cFaces, cFacei) - { - nbrFaces.insert(cFaces[cFacei]); - } + nbrFaces.insertMany(cFaces); } } nbrFaces.sync(mesh_); @@ -949,20 +944,14 @@ bool Foam::motionSmootherAlgo::scaleMesh label own = mesh_.faceOwner()[iter.key()]; const cell& ownFaces = mesh_.cells()[own]; - forAll(ownFaces, cfI) - { - newWrongFaces.insert(ownFaces[cfI]); - } + newWrongFaces.insertMany(ownFaces); if (iter.key() < mesh_.nInternalFaces()) { label nei = mesh_.faceNeighbour()[iter.key()]; const cell& neiFaces = mesh_.cells()[nei]; - forAll(neiFaces, cfI) - { - newWrongFaces.insert(neiFaces[cfI]); - } + newWrongFaces.insertMany(neiFaces); } } wrongFaces.transfer(newWrongFaces); diff --git a/src/dynamicMesh/perfectInterface/perfectInterface.C b/src/dynamicMesh/perfectInterface/perfectInterface.C index bca3bda87b3e8743c2b99c31637d2d3d5cfdd708..81cf5fb4a62ffc47a9d5b1178536383abf66e323 100644 --- a/src/dynamicMesh/perfectInterface/perfectInterface.C +++ b/src/dynamicMesh/perfectInterface/perfectInterface.C @@ -262,10 +262,7 @@ void Foam::perfectInterface::setRefinement { const labelList& pFaces = mesh.pointFaces()[meshPointi]; - forAll(pFaces, pFacei) - { - affectedFaces.insert(pFaces[pFacei]); - } + affectedFaces.insertMany(pFaces); } } forAll(pp1, i) diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/hexRef8.C b/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/hexRef8.C index 9bee5b3d068d973512b4cf1221a5afdc38fa9260..e57fa3fd33efb1a3ef5e8c39d29914505b601815 100644 --- a/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/hexRef8.C +++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/hexRef8.C @@ -5523,10 +5523,7 @@ void Foam::hexRef8::setUnrefinement { const labelList& pCells = mesh_.pointCells(splitPointLabels[i]); - forAll(pCells, j) - { - cSet.insert(pCells[j]); - } + cSet.insertMany(pCells); } cSet.write(); @@ -5550,10 +5547,7 @@ void Foam::hexRef8::setUnrefinement { const labelList& pFaces = mesh_.pointFaces()[splitPointLabels[i]]; - forAll(pFaces, j) - { - splitFaces.insert(pFaces[j]); - } + splitFaces.insertMany(pFaces); } // Check with faceRemover what faces will get removed. Note that this diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/removePoints.C b/src/dynamicMesh/polyTopoChange/polyTopoChange/removePoints.C index d5a3c44600ff9b36dba4944e98d308126c833858..7b6b04cc6b095acfed12dbfa1a7c88bb67a77362 100644 --- a/src/dynamicMesh/polyTopoChange/polyTopoChange/removePoints.C +++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/removePoints.C @@ -343,10 +343,7 @@ void Foam::removePoints::setRefinement // Store faces affected const labelList& pFaces = mesh_.pointFaces()[pointi]; - forAll(pFaces, i) - { - facesAffected.insert(pFaces[i]); - } + facesAffected.insertMany(pFaces); } } diff --git a/src/dynamicMesh/slidingInterface/coupleSlidingInterface.C b/src/dynamicMesh/slidingInterface/coupleSlidingInterface.C index edcdbb64a025f4f7c5f7ab14025d1b622acf72ac..88b3f36be840c9cfa5318da3b83890d19fa3b1dc 100644 --- a/src/dynamicMesh/slidingInterface/coupleSlidingInterface.C +++ b/src/dynamicMesh/slidingInterface/coupleSlidingInterface.C @@ -186,10 +186,7 @@ void Foam::slidingInterface::coupleInterface(polyTopoChange& ref) const // edges for (const label slaveEdgei : curSlaveEdges) { - usedMasterEdges[slaveEdgei].insert - ( - curMasterEdges - ); + usedMasterEdges[slaveEdgei].insertMany(curMasterEdges); } } else if (slavePointEdgeHits[pointi] > -1) @@ -214,7 +211,7 @@ void Foam::slidingInterface::coupleInterface(polyTopoChange& ref) const { const labelList& curMasterEdges = masterPointEdges[masterPointi]; - usedMasterEdges[masterPointEdgeHits[masterPointi]].insert + usedMasterEdges[masterPointEdgeHits[masterPointi]].insertMany ( curMasterEdges ); @@ -574,10 +571,7 @@ void Foam::slidingInterface::coupleInterface(polyTopoChange& ref) const // << masterPatch.localFaces()[facei] // << endl; - curMasterEdgesMap.insert - ( - masterFaceEdges[facei] - ); + curMasterEdgesMap.insertMany(masterFaceEdges[facei]); } const labelList curMasterEdges(curMasterEdgesMap.toc()); diff --git a/src/dynamicMesh/slidingInterface/slidingInterfaceProjectPoints.C b/src/dynamicMesh/slidingInterface/slidingInterfaceProjectPoints.C index 2969cfa1a7c486e5e7a1bf1451d7a731ae83a569..c1ff91566f178d03ce245ff6b11369edaa835391 100644 --- a/src/dynamicMesh/slidingInterface/slidingInterfaceProjectPoints.C +++ b/src/dynamicMesh/slidingInterface/slidingInterfaceProjectPoints.C @@ -880,8 +880,7 @@ bool Foam::slidingInterface::projectPoints() const for (const label facei : curFaceMap) { const face& f = masterLocalFaces[facei]; - - curPointMap.insert(f); // Insert all face points + curPointMap.insertMany(f); // Insert all face points } const labelList curMasterPoints = curPointMap.toc(); diff --git a/src/finiteArea/faMesh/faMeshDemandDrivenData.C b/src/finiteArea/faMesh/faMeshDemandDrivenData.C index 01d3692ae4e94613094e03df25d6d407deb57559..c64a1511e6b3e1547fb791f4cc96d8bc5eb53eb9 100644 --- a/src/finiteArea/faMesh/faMeshDemandDrivenData.C +++ b/src/finiteArea/faMesh/faMeshDemandDrivenData.C @@ -1455,10 +1455,8 @@ void Foam::faMesh::calcPointAreaNormalsByQuadricsFit() const procPatch.neighbPoints()[nonGlobalPatchPoints[pointI]]; labelHashSet faceSet; - forAll(pointFaces[curPoint], faceI) - { - faceSet.insert(pointFaces[curPoint][faceI]); - } + faceSet.insertMany(pointFaces[curPoint]); + labelList curFaces = faceSet.toc(); labelHashSet pointSet; diff --git a/src/finiteVolume/functionObjects/fieldSelection/fieldSelectionTemplates.C b/src/finiteVolume/functionObjects/fieldSelection/fieldSelectionTemplates.C index 80c476a44e141c6096a4be814eb96d21aec4643e..653de0edfaa61fc101a86f07429cb80c8f1b1ed9 100644 --- a/src/finiteVolume/functionObjects/fieldSelection/fieldSelectionTemplates.C +++ b/src/finiteVolume/functionObjects/fieldSelection/fieldSelectionTemplates.C @@ -34,13 +34,10 @@ void Foam::functionObjects::fieldSelection::addRegistered wordHashSet& set ) const { - DynamicList<word> names; for (const wordRe& name : *this) { - names.append(obr_.names<Type>(name)); + set.insertMany(obr_.names<Type>(name)); } - - set.insert(names); } diff --git a/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelectionTemplates.C b/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelectionTemplates.C index ecfa95bdb4a2e4f6b2e52ec3c2541be779e37750..9ea26d114f7764dd63417ac5f996d455010e833e 100644 --- a/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelectionTemplates.C +++ b/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelectionTemplates.C @@ -26,7 +26,6 @@ License #include "IOobjectList.H" #include "GeometricField.H" #include "fvMesh.H" -#include "DynamicList.H" // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * // @@ -37,14 +36,10 @@ void Foam::functionObjects::fileFieldSelection::addFromFile wordHashSet& set ) const { - DynamicList<word> names(this->size()); - for (const wordRe& fieldName : *this) { - names.append(allFileObjects.names(Type::typeName, fieldName)); + set.insertMany(allFileObjects.names(Type::typeName, fieldName)); } - - set.insert(names); } diff --git a/src/finiteVolume/fvMatrices/solvers/isoAdvection/isoAdvection/isoAdvection.C b/src/finiteVolume/fvMatrices/solvers/isoAdvection/isoAdvection/isoAdvection.C index cb101d95ff7289f2da995d31db2dbe9be1462a91..57de8b3cce63544a00dd74957fbb5ec6e0e99947 100644 --- a/src/finiteVolume/fvMatrices/solvers/isoAdvection/isoAdvection/isoAdvection.C +++ b/src/finiteVolume/fvMatrices/solvers/isoAdvection/isoAdvection/isoAdvection.C @@ -1050,10 +1050,7 @@ void Foam::isoAdvection::writeSurfaceCells() const ) ); - forAll(surfCells_, i) - { - cSet.insert(surfCells_[i]); - } + cSet.insertMany(surfCells_); cSet.write(); } diff --git a/src/finiteVolume/fvMesh/extendedStencil/cellToCell/globalIndexStencils/cellToCellStencil.C b/src/finiteVolume/fvMesh/extendedStencil/cellToCell/globalIndexStencils/cellToCellStencil.C index afbb8a90feff8af340af0d1f25151fe1b492b0c3..cec896d7e36ad853af26a96c89457d7cf2e0fe88 100644 --- a/src/finiteVolume/fvMesh/extendedStencil/cellToCell/globalIndexStencils/cellToCellStencil.C +++ b/src/finiteVolume/fvMesh/extendedStencil/cellToCell/globalIndexStencils/cellToCellStencil.C @@ -248,10 +248,7 @@ void Foam::cellToCellStencil::unionEqOp::operator() else { labelHashSet set(x); - forAll(y, i) - { - set.insert(y[i]); - } + set.insertMany(y); x = set.toc(); } } diff --git a/src/finiteVolume/fvMesh/extendedStencil/cellToFace/globalIndexStencils/cellToFaceStencil.C b/src/finiteVolume/fvMesh/extendedStencil/cellToFace/globalIndexStencils/cellToFaceStencil.C index 46275af0ffb7b7dfe182fd299aaf93adce6772ca..2a78462fa2f5e1dd795a4301c0add66dc206b77b 100644 --- a/src/finiteVolume/fvMesh/extendedStencil/cellToFace/globalIndexStencils/cellToFaceStencil.C +++ b/src/finiteVolume/fvMesh/extendedStencil/cellToFace/globalIndexStencils/cellToFaceStencil.C @@ -249,10 +249,7 @@ void Foam::cellToFaceStencil::unionEqOp::operator() else { labelHashSet set(x); - forAll(y, i) - { - set.insert(y[i]); - } + set.insertMany(y); x = set.toc(); } } @@ -391,19 +388,11 @@ void Foam::cellToFaceStencil::calcFaceStencil const labelList& ownCCells = globalCellCells[own[facei]]; label globalOwn = ownCCells[0]; - // Insert cellCells - forAll(ownCCells, i) - { - faceStencilSet.insert(ownCCells[i]); - } + faceStencilSet.insertMany(ownCCells); // Insert cellCells const labelList& neiCCells = globalCellCells[nei[facei]]; label globalNei = neiCCells[0]; - // Insert cellCells - forAll(neiCCells, i) - { - faceStencilSet.insert(neiCCells[i]); - } + faceStencilSet.insertMany(neiCCells); // Insert cellCells // Guarantee owner first, neighbour second. faceStencil[facei].setSize(faceStencilSet.size()); @@ -433,19 +422,13 @@ void Foam::cellToFaceStencil::calcFaceStencil const labelList& ownCCells = globalCellCells[own[facei]]; label globalOwn = ownCCells[0]; - forAll(ownCCells, i) - { - faceStencilSet.insert(ownCCells[i]); - } + faceStencilSet.insertMany(ownCCells); // And the neighbours of the coupled cell const labelList& neiCCells = neiGlobalCellCells[facei-mesh_.nInternalFaces()]; label globalNei = neiCCells[0]; - forAll(neiCCells, i) - { - faceStencilSet.insert(neiCCells[i]); - } + faceStencilSet.insertMany(neiCCells); // Guarantee owner first, neighbour second. faceStencil[facei].setSize(faceStencilSet.size()); @@ -475,10 +458,7 @@ void Foam::cellToFaceStencil::calcFaceStencil const labelList& ownCCells = globalCellCells[own[facei]]; label globalOwn = ownCCells[0]; - forAll(ownCCells, i) - { - faceStencilSet.insert(ownCCells[i]); - } + faceStencilSet.insertMany(ownCCells); // Guarantee owner first faceStencil[facei].setSize(faceStencilSet.size()); diff --git a/src/functionObjects/field/turbulenceFields/turbulenceFields.C b/src/functionObjects/field/turbulenceFields/turbulenceFields.C index 6c697271de62a7d4849267387f3e127929a13ea2..054ad322cbea005b24396ab82ca189c1913a0501 100644 --- a/src/functionObjects/field/turbulenceFields/turbulenceFields.C +++ b/src/functionObjects/field/turbulenceFields/turbulenceFields.C @@ -146,16 +146,16 @@ bool Foam::functionObjects::turbulenceFields::read(const dictionary& dict) } else { - fieldSet_.insert(wordList(dict.lookup("fields"))); + fieldSet_.insertMany(wordList(dict.lookup("fields"))); } Info<< type() << " " << name() << ": "; if (fieldSet_.size()) { Info<< "storing fields:" << nl; - forAllConstIter(wordHashSet, fieldSet_, iter) + for (const word& f : fieldSet_) { - Info<< " " << modelName << ':' << iter.key() << nl; + Info<< " " << modelName << ':' << f << nl; } Info<< endl; } @@ -177,9 +177,8 @@ bool Foam::functionObjects::turbulenceFields::execute() const compressible::turbulenceModel& model = obr_.lookupObject<compressible::turbulenceModel>(modelName); - forAllConstIter(wordHashSet, fieldSet_, iter) + for (const word& f : fieldSet_) { - const word& f = iter.key(); switch (compressibleFieldNames_[f]) { case cfK: @@ -250,9 +249,8 @@ bool Foam::functionObjects::turbulenceFields::execute() const incompressible::turbulenceModel& model = obr_.lookupObject<incompressible::turbulenceModel>(modelName); - forAllConstIter(wordHashSet, fieldSet_, iter) + for (const word& f : fieldSet_) { - const word& f = iter.key(); switch (incompressibleFieldNames_[f]) { case ifK: @@ -315,9 +313,9 @@ bool Foam::functionObjects::turbulenceFields::execute() bool Foam::functionObjects::turbulenceFields::write() { - forAllConstIter(wordHashSet, fieldSet_, iter) + for (const word& f : fieldSet_) { - const word fieldName = modelName + ':' + iter.key(); + const word fieldName = modelName + ':' + f; writeObject(fieldName); } diff --git a/src/lagrangian/intermediate/submodels/CloudFunctionObjects/ParticleErosion/ParticleErosion.C b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/ParticleErosion/ParticleErosion.C index fec798351bd255d5398830cedfdaaf4fbbeea73f..4591d067f38c83560ddbf99b8c845a264b0762a5 100644 --- a/src/lagrangian/intermediate/submodels/CloudFunctionObjects/ParticleErosion/ParticleErosion.C +++ b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/ParticleErosion/ParticleErosion.C @@ -92,7 +92,7 @@ Foam::ParticleErosion<CloudType>::ParticleErosion << endl; } - uniqIds.insert(ids); + uniqIds.insertMany(ids); } patchIDs_ = uniqIds.sortedToc(); diff --git a/src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchPostProcessing/PatchPostProcessing.C b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchPostProcessing/PatchPostProcessing.C index 21752df47fdc08c6bc5b5408011787c2733793d5..6e849578d058635f5e7b3c819a5e0365537d1263 100644 --- a/src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchPostProcessing/PatchPostProcessing.C +++ b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchPostProcessing/PatchPostProcessing.C @@ -149,7 +149,7 @@ Foam::PatchPostProcessing<CloudType>::PatchPostProcessing << endl; } - uniqIds.insert(ids); + uniqIds.insertMany(ids); } patchIDs_ = uniqIds.sortedToc(); diff --git a/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C b/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C index ca7765e8b96a0fa8a317cba0ea9b9c5a013b8128..d8393007db0cf0cbe58b331597b1908191c111a2 100644 --- a/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C +++ b/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C @@ -1011,7 +1011,7 @@ Foam::label Foam::meshRefinement::splitFacesUndo { const labelList grownFaces(growFaceCellFace(errorFaces)); errorFaces.clear(); - errorFaces.insert(grownFaces); + errorFaces.insertMany(grownFaces); } diff --git a/src/mesh/snappyHexMesh/meshRefinement/meshRefinementBaffles.C b/src/mesh/snappyHexMesh/meshRefinement/meshRefinementBaffles.C index 62011f5545204059dfecc872c869788bd3e10f7f..16115116a664ff14721717ab9ba72cf9be02b14e 100644 --- a/src/mesh/snappyHexMesh/meshRefinement/meshRefinementBaffles.C +++ b/src/mesh/snappyHexMesh/meshRefinement/meshRefinementBaffles.C @@ -625,10 +625,7 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::createBaffles { const cell& ownFaces = mesh_.cells()[mesh_.faceOwner()[faceI]]; - forAll(ownFaces, i) - { - baffledFacesSet.insert(ownFaces[i]); - } + baffledFacesSet.insertMany(ownFaces); } } // Pick up neighbour side of baffle (added faces) @@ -640,10 +637,7 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::createBaffles { const cell& ownFaces = mesh_.cells()[mesh_.faceOwner()[faceI]]; - forAll(ownFaces, i) - { - baffledFacesSet.insert(ownFaces[i]); - } + baffledFacesSet.insertMany(ownFaces); } } baffledFacesSet.sync(mesh_); diff --git a/src/mesh/snappyHexMesh/meshRefinement/meshRefinementMerge.C b/src/mesh/snappyHexMesh/meshRefinement/meshRefinementMerge.C index aecae5267481de2220f0006e7f7e5aa9f4793513..e5df4137334bed2948617183e6c887c724628a6c 100644 --- a/src/mesh/snappyHexMesh/meshRefinement/meshRefinementMerge.C +++ b/src/mesh/snappyHexMesh/meshRefinement/meshRefinementMerge.C @@ -227,19 +227,13 @@ Foam::label Foam::meshRefinement::mergePatchFaces // // const cell& ownFaces = cells[mesh_.faceOwner()[faceI]]; // -// forAll(ownFaces, i) -// { -// retestFaces.insert(ownFaces[i]); -// } +// retestFaces.insertMany(ownFaces); // // if (mesh_.isInternalFace(faceI)) // { // const cell& neiFaces = cells[mesh_.faceNeighbour()[faceI]]; // -// forAll(neiFaces, i) -// { -// retestFaces.insert(neiFaces[i]); -// } +// retestFaces.insertMany(neiFaces); // } // } // updateMesh(map, retestFaces.toc()); @@ -337,10 +331,7 @@ Foam::label Foam::meshRefinement::mergePatchFacesUndo faceSet allSets(mesh_, "allFaceSets", allFaceSets.size()); forAll(allFaceSets, setI) { - forAll(allFaceSets[setI], i) - { - allSets.insert(allFaceSets[setI][i]); - } + allSets.insertMany(allFaceSets[setI]); } Pout<< "Writing all faces to be merged to set " << allSets.objectPath() << endl; diff --git a/src/meshTools/cellClassification/cellClassification.C b/src/meshTools/cellClassification/cellClassification.C index 294ececd2ef6c9f650c5a89a7c2da01b7fbcb589..3a26f9785166b9562c1175fdb81a71cdbd8ea628 100644 --- a/src/meshTools/cellClassification/cellClassification.C +++ b/src/meshTools/cellClassification/cellClassification.C @@ -300,10 +300,7 @@ void Foam::cellClassification::markCells // Mark faces of celli const labelList& myFaces = mesh_.cells()[celli]; - forAll(myFaces, myFacei) - { - outsideFacesMap.insert(myFaces[myFacei]); - } + outsideFacesMap.insertMany(myFaces); } } diff --git a/src/meshTools/cellDist/cellDistFuncs.C b/src/meshTools/cellDist/cellDistFuncs.C index 58b60a425866c7bea72fa67a3a039772a922d4e2..718807bd89c372ab9de0df3ab7f3cca319e2c02d 100644 --- a/src/meshTools/cellDist/cellDistFuncs.C +++ b/src/meshTools/cellDist/cellDistFuncs.C @@ -172,11 +172,7 @@ Foam::label Foam::cellDistFuncs::getPointNeighbours forAll(f, fp) { const labelList& pointNbs = patch.pointFaces()[f[fp]]; - - forAll(pointNbs, i) - { - nbs.insert(pointNbs[i]); - } + nbs.insertMany(pointNbs); } // Subtract ours. diff --git a/src/meshTools/meshTools/meshTools.C b/src/meshTools/meshTools/meshTools.C index cb90a991c9995729a236f7edcc0ef7a367180f8e..4caac1345177d687a45657e90eecca156df1aa1f 100644 --- a/src/meshTools/meshTools/meshTools.C +++ b/src/meshTools/meshTools/meshTools.C @@ -301,11 +301,7 @@ void Foam::meshTools::writeOBJ forAll(cellLabels, i) { const cell& cFaces = cells[cellLabels[i]]; - - forAll(cFaces, j) - { - usedFaces.insert(cFaces[j]); - } + usedFaces.insertMany(cFaces); } writeOBJ(os, faces, points, usedFaces.toc()); diff --git a/src/meshTools/sets/faceSources/normalToFace/normalToFace.C b/src/meshTools/sets/faceSources/normalToFace/normalToFace.C index eb289aa68c0780ee7094e1e31a6afc7796356cb9..576aeae449499ff29e94ae22c769e275a7c7cd2c 100644 --- a/src/meshTools/sets/faceSources/normalToFace/normalToFace.C +++ b/src/meshTools/sets/faceSources/normalToFace/normalToFace.C @@ -160,10 +160,7 @@ void Foam::normalToFace::applyToSet } } - forAll(toBeRemoved, i) - { - set.erase(toBeRemoved[i]); - } + set.eraseMany(toBeRemoved); } } diff --git a/src/meshTools/triSurface/triSurfaceTools/triSurfaceTools.C b/src/meshTools/triSurface/triSurfaceTools/triSurfaceTools.C index 4b48447d2a7139c0f47b9d75d4559176c491e5b1..5c546362ac23a889c839de35858c11619268c319 100644 --- a/src/meshTools/triSurface/triSurfaceTools/triSurfaceTools.C +++ b/src/meshTools/triSurface/triSurfaceTools/triSurfaceTools.C @@ -384,11 +384,7 @@ Foam::labelHashSet Foam::triSurfaceTools::getCollapsedFaces const labelList& myFaces = surf.edgeFaces()[edgeI]; labelHashSet facesToBeCollapsed(2*myFaces.size()); - - forAll(myFaces, myFacei) - { - facesToBeCollapsed.insert(myFaces[myFacei]); - } + facesToBeCollapsed.insertMany(myFaces); // From faces using v1 check if they share an edge with faces // using v2. diff --git a/src/parallel/decompose/decompositionMethods/structuredDecomp/structuredDecomp.C b/src/parallel/decompose/decompositionMethods/structuredDecomp/structuredDecomp.C index a2a68a871ecbb439b28c521517243dfd2e977548..a44e4b64a48266fa98b6a4526db7278d76fc8bc4 100644 --- a/src/parallel/decompose/decompositionMethods/structuredDecomp/structuredDecomp.C +++ b/src/parallel/decompose/decompositionMethods/structuredDecomp/structuredDecomp.C @@ -85,7 +85,7 @@ Foam::labelList Foam::structuredDecomp::decompose labelHashSet patchCells(2*nFaces); for (const label patchi : patchIDs) { - patchCells.insert(pbm[patchi].faceCells()); + patchCells.insertMany(pbm[patchi].faceCells()); } // Subset the layer of cells next to the patch diff --git a/src/regionModels/surfaceFilmModels/submodels/kinematic/injectionModel/injectionModelList/injectionModelList.C b/src/regionModels/surfaceFilmModels/submodels/kinematic/injectionModel/injectionModelList/injectionModelList.C index c71833509fc48e7be6374cc9d5648d1b1b9ef92a..166702793337a5479d403abdd1a5292e84330647 100644 --- a/src/regionModels/surfaceFilmModels/submodels/kinematic/injectionModel/injectionModelList/injectionModelList.C +++ b/src/regionModels/surfaceFilmModels/submodels/kinematic/injectionModel/injectionModelList/injectionModelList.C @@ -62,11 +62,7 @@ injectionModelList::injectionModelList { const wordList activeModels(dict.lookup("injectionModels")); - wordHashSet models; - forAll(activeModels, i) - { - models.insert(activeModels[i]); - } + wordHashSet models(activeModels); Info<< " Selecting film injection models" << endl; if (models.size() > 0) @@ -74,9 +70,8 @@ injectionModelList::injectionModelList this->setSize(models.size()); label i = 0; - forAllConstIter(wordHashSet, models, iter) + for (const word& model : models) { - const word& model = iter.key(); set(i, injectionModel::New(film, dict, model)); i++; } diff --git a/src/regionModels/surfaceFilmModels/submodels/kinematic/transferModels/transferModelList/transferModelList.C b/src/regionModels/surfaceFilmModels/submodels/kinematic/transferModels/transferModelList/transferModelList.C index 123713b26b587f2eab42572d9281bedcb9ee565b..b3b0f9ef9c29bc8a3a6dd31c9203092e9f2b1a6d 100644 --- a/src/regionModels/surfaceFilmModels/submodels/kinematic/transferModels/transferModelList/transferModelList.C +++ b/src/regionModels/surfaceFilmModels/submodels/kinematic/transferModels/transferModelList/transferModelList.C @@ -65,11 +65,7 @@ transferModelList::transferModelList dict.lookupOrDefault("transferModels", wordList()) ); - wordHashSet models; - forAll(activeModels, i) - { - models.insert(activeModels[i]); - } + wordHashSet models(activeModels); Info<< " Selecting film transfer models" << endl; if (models.size() > 0) @@ -77,9 +73,8 @@ transferModelList::transferModelList this->setSize(models.size()); label i = 0; - forAllConstIter(wordHashSet, models, iter) + for (const word& model : models) { - const word& model = iter.key(); set(i, transferModel::New(film, dict, model)); i++; } diff --git a/src/renumber/renumberMethods/structuredRenumber/structuredRenumber.C b/src/renumber/renumberMethods/structuredRenumber/structuredRenumber.C index 2ee8a9f2765cdfdd967eee435cda889edecb251a..d2c49eada057fb07139c386f56faedc4b2ffb9e8 100644 --- a/src/renumber/renumberMethods/structuredRenumber/structuredRenumber.C +++ b/src/renumber/renumberMethods/structuredRenumber/structuredRenumber.C @@ -158,13 +158,9 @@ Foam::labelList Foam::structuredRenumber::renumber // Extract a submesh. labelHashSet patchCells(2*nFaces); - forAllConstIter(labelHashSet, patchIDs, iter) + for (const label patchId : patchIDs) { - const labelUList& fc = pbm[iter.key()].faceCells(); - forAll(fc, i) - { - patchCells.insert(fc[i]); - } + patchCells.insertMany(pbm[patchId].faceCells()); } label nTotalSeeds = returnReduce(patchCells.size(), sumOp<label>()); diff --git a/src/sampling/probes/probes.C b/src/sampling/probes/probes.C index 489c8e069e6146ecb437cff56a8beac49d675806..ad9c9fdb074aa34a177f7593b81ae2edb626ec0b 100644 --- a/src/sampling/probes/probes.C +++ b/src/sampling/probes/probes.C @@ -177,17 +177,17 @@ Foam::label Foam::probes::prepare() { wordHashSet currentFields; - currentFields.insert(scalarFields_); - currentFields.insert(vectorFields_); - currentFields.insert(sphericalTensorFields_); - currentFields.insert(symmTensorFields_); - currentFields.insert(tensorFields_); - - currentFields.insert(surfaceScalarFields_); - currentFields.insert(surfaceVectorFields_); - currentFields.insert(surfaceSphericalTensorFields_); - currentFields.insert(surfaceSymmTensorFields_); - currentFields.insert(surfaceTensorFields_); + currentFields.insertMany(scalarFields_); + currentFields.insertMany(vectorFields_); + currentFields.insertMany(sphericalTensorFields_); + currentFields.insertMany(symmTensorFields_); + currentFields.insertMany(tensorFields_); + + currentFields.insertMany(surfaceScalarFields_); + currentFields.insertMany(surfaceVectorFields_); + currentFields.insertMany(surfaceSphericalTensorFields_); + currentFields.insertMany(surfaceSymmTensorFields_); + currentFields.insertMany(surfaceTensorFields_); DebugInfo << "Probing fields: " << currentFields << nl @@ -229,10 +229,8 @@ Foam::label Foam::probes::prepare() } // currentFields now just has the new fields - open streams for them - forAllConstIter(wordHashSet, currentFields, iter) + for (const word& fieldName : currentFields) { - const word& fieldName = iter.key(); - // Create directory if does not exist. mkDir(probeDir); diff --git a/src/sampling/surfMeshSampler/surfMeshSamplers/surfMeshSamplers.C b/src/sampling/surfMeshSampler/surfMeshSamplers/surfMeshSamplers.C index 7172d8164ae5d9deacb95ad48e2ca1b486ca0189..8654729b8e6a8bcfc6dcd90c5763ae27d8b2b8ed 100644 --- a/src/sampling/surfMeshSampler/surfMeshSamplers/surfMeshSamplers.C +++ b/src/sampling/surfMeshSampler/surfMeshSamplers/surfMeshSamplers.C @@ -236,11 +236,11 @@ bool Foam::surfMeshSamplers::execute() // The acceptable fields wordHashSet acceptable(added); - acceptable.insert(acceptType<scalar>()); - acceptable.insert(acceptType<vector>()); - acceptable.insert(acceptType<sphericalTensor>()); - acceptable.insert(acceptType<symmTensor>()); - acceptable.insert(acceptType<tensor>()); + acceptable.insertMany(acceptType<scalar>()); + acceptable.insertMany(acceptType<vector>()); + acceptable.insertMany(acceptType<sphericalTensor>()); + acceptable.insertMany(acceptType<symmTensor>()); + acceptable.insertMany(acceptType<tensor>()); const wordList fields = acceptable.sortedToc(); if (!fields.empty())