Commit 6b6b36af authored by Mark Olesen's avatar Mark Olesen
Browse files

STYLE: revert bitSet/HashSet setMany() to set() method (issue #837)

- improves backward compatibility and more naming consistency.
  Retain setMany(iter1, iter2) to avoid ambiguity with the
  PackedList::set(index, value) method.
parent 3de9b2f6
......@@ -188,10 +188,10 @@ int main(int argc, char *argv[])
Info<< "setB : " << setB << endl;
labelPair pair(12, 15);
setB.setMany(pair);
setB.set(pair);
Info<< "setB : " << setB << endl;
setB.unsetMany(pair);
setB.unset(pair);
labelHashSet setC(1);
......@@ -257,7 +257,7 @@ int main(int argc, char *argv[])
someLst[elemI] = elemI*elemI;
}
label added = setD.setMany(someLst);
label added = setD.set(someLst);
Info<< "added " << added << " from " << someLst.size() << endl;
Info<< "setD : " << flatOutput(setD) << endl;
......
......@@ -294,7 +294,7 @@ int main(int argc, char *argv[])
Info<< "\nclear/assign from labelList\n";
list4.clear();
list4.setMany(labelList{0, 1, 2, 3, 12, 13, 14, 19, 20, 21});
list4.set(labelList{0, 1, 2, 3, 12, 13, 14, 19, 20, 21});
report(list4, true);
......
......@@ -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.insertMany(newIndices.toc());
e4.insert(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.insertMany(otherIndices);
e4.insert(otherIndices);
printInfo(e4);
e4.start() = e4.end();
Info<< "erase from list: " << otherIndices << nl;
Info<< "removed " << e4.eraseMany(otherIndices) << " values" << nl;
Info<< "removed " << e4.erase(otherIndices) << " values" << nl;
printInfo(e4);
for (label i : {-1, 0, 1, 3})
......
......@@ -374,7 +374,7 @@ void Foam::cellSplitter::setRefinement
const cell& cFaces = mesh_.cells()[celli];
faceUpToDate.unsetMany(cFaces);
faceUpToDate.unset(cFaces);
}
forAll(faceUpToDate, facei)
......
......@@ -120,7 +120,7 @@ int main(int argc, char *argv[])
{
const labelList& pCells = mesh.pointCells()[meshPointi];
cutCells.insertMany(pCells);
cutCells.insert(pCells);
}
}
......@@ -153,7 +153,7 @@ int main(int argc, char *argv[])
const polyPatch& pp = mesh.boundaryMesh()[patchi];
const labelList& meshPoints = pp.meshPoints();
vertOnPatch.setMany(meshPoints);
vertOnPatch.set(meshPoints);
}
for (const label patchi : patchSet)
......
......@@ -184,7 +184,7 @@ int main(int argc, char *argv[])
const DynamicList<label>& bin = bins[binI];
cellSet cells(mesh, "vol" + name(binI), bin.size());
cells.insertMany(bin);
cells.insert(bin);
Info<< " " << lowerLimits[binI] << " .. " << upperLimits[binI]
<< " : writing " << bin.size() << " cells to cellSet "
......
......@@ -633,7 +633,7 @@ int main(int argc, char *argv[])
);
cellSet cutSet(mesh, "cutSet", cutCells.size());
cutSet.insertMany(cutCells);
cutSet.insert(cutCells);
// Gets cuts across cells from cuts through edges.
Info<< "Writing " << cutSet.size() << " cells to cut to cellSet "
......
......@@ -956,7 +956,7 @@ int main(int argc, char *argv[])
forAll(dofVertIndices, patchi)
{
const labelList& foamVerts = dofVertIndices[patchi];
dofGroups[patchi].insertMany(foamVerts);
dofGroups[patchi].insert(foamVerts);
}
List<DynamicList<face>> dynPatchFaces(dofVertIndices.size());
......
......@@ -344,7 +344,7 @@ void writePointCells
{
const labelList& cEdges = mesh.cellEdges()[pCells[i]];
allEdges.insertMany(cEdges);
allEdges.insert(cEdges);
}
......
......@@ -795,7 +795,7 @@ int main(int argc, char *argv[])
forAll(addedCells, facei)
{
const labelList& aCells = addedCells[facei];
addedCellsSet.insertMany(aCells);
addedCellsSet.insert(aCells);
}
}
}
......
......@@ -527,7 +527,7 @@ label findUncoveredPatchFace
{
// Make set of extruded faces.
labelHashSet extrudeFaceSet(extrudeMeshFaces.size());
extrudeFaceSet.insertMany(extrudeMeshFaces);
extrudeFaceSet.insert(extrudeMeshFaces);
const polyBoundaryMesh& pbm = mesh.boundaryMesh();
const labelList& eFaces = mesh.edgeFaces()[meshEdgeI];
......@@ -561,7 +561,7 @@ label findUncoveredCyclicPatchFace
{
// Make set of extruded faces.
labelHashSet extrudeFaceSet(extrudeMeshFaces.size());
extrudeFaceSet.insertMany(extrudeMeshFaces);
extrudeFaceSet.insert(extrudeMeshFaces);
const polyBoundaryMesh& pbm = mesh.boundaryMesh();
const labelList& eFaces = mesh.edgeFaces()[meshEdgeI];
......
......@@ -1053,7 +1053,7 @@ Foam::labelHashSet Foam::conformalVoronoiMesh::checkPolyMeshQuality
nInvalidPolyhedra++;
wrongFaces.insertMany(cells[cI]);
wrongFaces.insert(cells[cI]);
}
}
......@@ -1093,7 +1093,7 @@ Foam::labelHashSet Foam::conformalVoronoiMesh::checkPolyMeshQuality
if (nInternalFaces[cI] <= 1)
{
oneInternalFaceCells++;
wrongFaces.insertMany(cells[cI]);
wrongFaces.insert(cells[cI]);
}
}
......@@ -1109,7 +1109,7 @@ Foam::labelHashSet Foam::conformalVoronoiMesh::checkPolyMeshQuality
{
const face f = pMesh.faces()[facei];
ptToBeLimited.setMany(f);
ptToBeLimited.set(f);
}
// // Limit connected cells
......@@ -1126,7 +1126,7 @@ Foam::labelHashSet Foam::conformalVoronoiMesh::checkPolyMeshQuality
// {
// label ptI = f[fPtI];
// const labelList& pC = ptCells[ptI];
// limitCells.insertMany(pC);
// limitCells.insert(pC);
// }
// }
......@@ -1136,7 +1136,7 @@ Foam::labelHashSet Foam::conformalVoronoiMesh::checkPolyMeshQuality
// {
// const labelList& cP = cellPts[celli];
// ptToBeLimited.setMany(cP);
// ptToBeLimited.set(cP);
// }
......@@ -2537,7 +2537,7 @@ void Foam::conformalVoronoiMesh::removeUnusedPoints
{
const face& f = faces[fI];
ptUsed.setMany(f);
ptUsed.set(f);
}
label pointi = 0;
......@@ -2587,8 +2587,8 @@ Foam::labelList Foam::conformalVoronoiMesh::removeUnusedCells
// Scan all faces to find all of the cells that are used
cellUsed.setMany(owner);
cellUsed.setMany(neighbour);
cellUsed.set(owner);
cellUsed.set(neighbour);
label celli = 0;
......
......@@ -1369,7 +1369,7 @@ Foam::labelHashSet Foam::conformalVoronoiMesh::findRemainingProtrusionSet
for (const label pointi : protrudingBoundaryPoints)
{
const labelList& pCells = mesh.pointCells()[pointi];
protrudingCells.insertMany(pCells);
protrudingCells.insert(pCells);
}
label protrudingCellsSize = protrudingCells.size();
......
......@@ -891,7 +891,7 @@ void Foam::meshDualiser::setRefinement
{
const labelList& fEdges = mesh_.faceEdges()[facei];
isBoundaryEdge.setMany(fEdges);
isBoundaryEdge.set(fEdges);
}
......
......@@ -349,7 +349,7 @@ int main(int argc, char *argv[])
forAll(oldToNew, oldCelli)
{
const labelList& added = oldToNew[oldCelli];
newCells.insertMany(added);
newCells.insert(added);
}
Info<< "Writing refined cells ("
......
......@@ -300,7 +300,7 @@ void Foam::regionSide::walkAllPointConnectedFaces
{
const labelList& fEdges = mesh.faceEdges()[facei];
regionEdges.insertMany(fEdges);
regionEdges.insert(fEdges);
}
......
......@@ -311,7 +311,7 @@ int main(int argc, char *argv[])
wordHashSet names;
forAllConstIters(rp, iter)
{
names.insertMany(iter.object());
names.insert(iter.object());
}
regionNames = names.sortedToc();
......
......@@ -451,7 +451,7 @@ void Foam::domainDecomposition::decomposeMesh()
const labelList& facePoints = fcs[mag(facei) - 1];
// Mark the face points as being used
pointsInUse.setMany(facePoints);
pointsInUse.set(facePoints);
}
procPointAddressing_[proci] = pointsInUse.sortedToc();
......
......@@ -186,7 +186,7 @@ int main(int argc, char *argv[])
wordHashSet names;
forAllConstIters(rp, iter)
{
names.insertMany(iter.object());
names.insert(iter.object());
}
regionNames = names.sortedToc();
......
......@@ -227,7 +227,7 @@ void Foam::vtkPVFoam::updateInfoLagrangian
for (const instant& t : dbPtr_().times())
{
names.insertMany
names.insert
(
readDir
(
......
......@@ -123,7 +123,7 @@ Foam::boundaryInfo::boundaryInfo(const Time& runTime, const word& regionName)
if (dict.found("inGroups"))
{
dict.lookup("inGroups") >> groups_[patchI];
allGroupNames_.insertMany(groups_[patchI]);
allGroupNames_.insert(groups_[patchI]);
}
}
}
......
......@@ -202,7 +202,7 @@ int main(int argc, char *argv[])
for (const wordRe& zoneName : zoneNames)
{
labelList zoneIDs = findStrings(zoneName, allZoneNames);
includeFaceZones.insertMany(zoneIDs);
includeFaceZones.insert(zoneIDs);
if (zoneIDs.empty())
{
......
Subproject commit d31e13e12b4d9b727b28d39bc34086f2cb75acfa
Subproject commit eaa7f6836a1950fe8d40c13952aa85a1062f7f91
......@@ -262,7 +262,7 @@ public:
// Setting single or multiple values
//- Single index/value assign
//- Assign a single index/value
using PackedList<1>::set;
//- Set specified bits from another bitset.
......@@ -346,29 +346,41 @@ public:
// Either increases the size of the bitSet or is a no-op.
inline bitSet& extend(const bitSet& other);
//- Set the locations listed by the iterator range,
// auto-vivify entries if needed.
//
// \return number of locations changed
template<class InputIter>
label setMany(InputIter first, InputIter last);
//- Set the listed locations to true.
// Does auto-vivify for non-existent entries.
inline void setMany(const labelUList& locations);
//
// \return number of locations changed
inline label set(const labelUList& locations);
//- Set the listed locations to true.
// Does auto-vivify for non-existent entries.
inline void setMany(const labelUIndList& locations);
//
// \return number of locations changed
inline label set(const labelUIndList& locations);
//- Set the locations listed by the iterator range,
// auto-vivify entries if needed.
//- Unset the locations listed by the iterator range,
//- never auto-vivify entries.
//
// \return number of locations changed
template<class InputIter>
void setMany(InputIter first, InputIter last);
label unset(InputIter first, InputIter last);
//- Unset the listed locations, never auto-vivifies.
inline void unsetMany(const labelUList& locations);
//
// \return number of locations changed
inline label unset(const labelUList& locations);
//- Unset the listed locations, never auto-vivifies.
inline void unsetMany(const labelUIndList& locations);
//- Unset the locations listed by the iterator range,
//- never auto-vivify entries.
template<class InputIter>
void unsetMany(InputIter first, InputIter last);
//
// \return number of locations changed
inline label unset(const labelUIndList& locations);
// Access helpers
......
......@@ -531,27 +531,27 @@ inline void Foam::bitSet::set(const bitSet& bitset)
}
inline void Foam::bitSet::setMany(const labelUList& locations)
inline Foam::label Foam::bitSet::set(const labelUList& locations)
{
setMany(locations.begin(), locations.end());
return setMany(locations.begin(), locations.end());
}
inline void Foam::bitSet::setMany(const labelUIndList& locations)
inline Foam::label Foam::bitSet::set(const labelUIndList& locations)
{
setMany(locations.begin(), locations.end());
return setMany(locations.begin(), locations.end());
}
inline void Foam::bitSet::unsetMany(const labelUList& locations)
inline Foam::label Foam::bitSet::unset(const labelUList& locations)
{
unsetMany(locations.begin(), locations.end());
return unset(locations.begin(), locations.end());
}
inline void Foam::bitSet::unsetMany(const labelUIndList& locations)
inline Foam::label Foam::bitSet::unset(const labelUIndList& locations)
{
unsetMany(locations.begin(), locations.end());
return unset(locations.begin(), locations.end());
}
......
......@@ -28,31 +28,45 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class InputIter>
void Foam::bitSet::setMany(InputIter first, InputIter last)
Foam::label Foam::bitSet::setMany(InputIter first, InputIter last)
{
// Check the max expected value first
const auto max = std::max_element(first, last);
const label len = (max != last ? (1 + *max) : 0);
label changed = 0;
if (len > 0)
{
reserve(len);
for (; first != last; ++first)
{
set(*first);
if (set(*first))
{
++changed;
}
}
}
return changed;
}
template<class InputIter>
void Foam::bitSet::unsetMany(InputIter first, InputIter last)
Foam::label Foam::bitSet::unset(InputIter first, InputIter last)
{
label changed = 0;
for (; first != last; ++first)
{
unset(*first);
if (unset(*first))
{
++changed;
}
}
return changed;
}
......
......@@ -42,7 +42,7 @@ inline Foam::label Foam::HashSet<Key, Hash>::assignMany
{
if (!this->capacity())
{
// Could be zero-sized from a previous transfer()?
// Zero-sized from a previous transfer()?
this->resize(2*nItems);
}
else
......@@ -155,7 +155,7 @@ inline Foam::label Foam::HashSet<Key, Hash>::insert
template<class Key, class Hash>
template<unsigned Size>
inline Foam::label Foam::HashSet<Key, Hash>::insertMany
inline Foam::label Foam::HashSet<Key, Hash>::insert
(
const FixedList<Key, Size>& list
)
......@@ -165,7 +165,7 @@ inline Foam::label Foam::HashSet<Key, Hash>::insertMany
template<class Key, class Hash>
inline Foam::label Foam::HashSet<Key, Hash>::insertMany
inline Foam::label Foam::HashSet<Key, Hash>::insert
(
const UList<Key>& list
)
......@@ -175,7 +175,7 @@ inline Foam::label Foam::HashSet<Key, Hash>::insertMany
template<class Key, class Hash>
inline Foam::label Foam::HashSet<Key, Hash>::insertMany
inline Foam::label Foam::HashSet<Key, Hash>::insert
(
const UIndirectList<Key>& list
)
......@@ -208,7 +208,7 @@ inline Foam::label Foam::HashSet<Key, Hash>::unset
template<class Key, class Hash>
template<unsigned Size>
inline Foam::label Foam::HashSet<Key, Hash>::unsetMany
inline Foam::label Foam::HashSet<Key, Hash>::unset
(
const FixedList<Key, Size>& list
)
......@@ -218,7 +218,7 @@ inline Foam::label Foam::HashSet<Key, Hash>::unsetMany
template<class Key, class Hash>
inline Foam::label Foam::HashSet<Key, Hash>::unsetMany
inline Foam::label Foam::HashSet<Key, Hash>::unset
(
const UList<Key>& list
)
......@@ -228,7 +228,7 @@ inline Foam::label Foam::HashSet<Key, Hash>::unsetMany
template<class Key, class Hash>
inline Foam::label Foam::HashSet<Key, Hash>::unsetMany
inline Foam::label Foam::HashSet<Key, Hash>::unset
(
const UIndirectList<Key>& list
)
......
......@@ -204,15 +204,15 @@ public:
//- Insert keys from the list of Key
// \return The number of new elements inserted
template<unsigned Size>
inline label insertMany(const FixedList<Key, Size>& list);
inline label insert(const FixedList<Key, Size>& list);
//- Insert keys from the list of Key
// \return The number of new elements inserted
inline label insertMany(const UList<Key>& list);
inline label insert(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);
inline label insert(const UIndirectList<Key>& list);
//- Same as insert (no value to overwrite)
template<class InputIter>
......@@ -229,27 +229,35 @@ public:
//- Same as insert (no value to overwrite)
template<unsigned Size>
inline label setMany(const FixedList<Key, Size>& list)
inline label set(const FixedList<Key, Size>& list)
{
return insertMany(list);
return insert(list);
}