Commit d17bc725 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: consistency of HashSet setMany(), insertMany() with packed-list version

- this also provides a better separation of the intent
  (ie, inserting a single value, or inserting multiply values)
parent 5d1fb235
......@@ -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;
......
......@@ -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})
......
......@@ -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;
......
......@@ -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);
}
}
......
......@@ -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 "
......
......@@ -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 "
......
......@@ -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());
......
......@@ -344,10 +344,7 @@ void writePointCells
{
const labelList& cEdges = mesh.cellEdges()[pCells[i]];
forAll(cEdges, i)
{
allEdges.insert(cEdges[i]);
}
allEdges.insertMany(cEdges);
}
......
......@@ -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);
}
}
}
......
......@@ -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];
......
......@@ -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);
// }
// }
......
......@@ -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();
......
......@@ -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 ("
......
......@@ -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);
}
......
......@@ -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();
......
......@@ -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();
......
......@@ -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);
......
......@@ -227,7 +227,7 @@ void Foam::vtkPVFoam::updateInfoLagrangian
for (const instant& t : dbPtr_().times())
{
names.insert
names.insertMany
(
readDir
(
......
......@@ -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]);
}
}
}
......
......@@ -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)
......
......@@ -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())
{
......
......@@ -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());
}