STYLE: avoid explicit use of 'word' as HashTable template parameter

- less clutter and typing to use the default template parameter when
  the key is 'word' anyhow.

- use EdgeMap instead of the longhand HashTable version where
  appropriate
This commit is contained in:
Mark Olesen
2017-05-10 13:44:27 +02:00
parent 4d126bfe2d
commit 8728e8353f
14 changed files with 87 additions and 110 deletions

View File

@ -924,8 +924,8 @@ int main(int argc, char *argv[])
} }
} }
HashTable<labelList,word> cellZones; HashTable<labelList> cellZones;
HashTable<labelList,word> faceZones; HashTable<labelList> faceZones;
List<bool> isAPatch(patchNames.size(),true); List<bool> isAPatch(patchNames.size(),true);
if (dofVertIndices.size()) if (dofVertIndices.size())

View File

@ -233,21 +233,16 @@ void Foam::vtkPVFoam::updateInfoPatches
if (meshPtr_) if (meshPtr_)
{ {
const polyBoundaryMesh& patches = meshPtr_->boundaryMesh(); const polyBoundaryMesh& patches = meshPtr_->boundaryMesh();
const HashTable<labelList, word>& groups = patches.groupPatchIDs(); const HashTable<labelList>& groups = patches.groupPatchIDs();
const wordList allPatchNames = patches.names(); const wordList allPatchNames = patches.names();
// Add patch groups // Add patch groups
// ~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~
for forAllConstIters(groups, iter)
(
HashTable<labelList, word>::const_iterator iter = groups.begin();
iter != groups.end();
++iter
)
{ {
const word& groupName = iter.key(); const word& groupName = iter.key();
const labelList& patchIDs = iter(); const labelList& patchIDs = iter.object();
label nFaces = 0; label nFaces = 0;
forAll(patchIDs, i) forAll(patchIDs, i)
@ -349,7 +344,7 @@ void Foam::vtkPVFoam::updateInfoPatches
// Add (non-zero) patch groups to the list of mesh parts // Add (non-zero) patch groups to the list of mesh parts
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HashTable<labelList, word> groups(patchEntries.size()); HashTable<labelList> groups(patchEntries.size());
forAll(patchEntries, patchi) forAll(patchEntries, patchi)
{ {
@ -360,7 +355,7 @@ void Foam::vtkPVFoam::updateInfoPatches
forAll(groupNames, groupI) forAll(groupNames, groupI)
{ {
HashTable<labelList, word>::iterator iter = groups.find HashTable<labelList>::iterator iter = groups.find
( (
groupNames[groupI] groupNames[groupI]
); );
@ -375,16 +370,10 @@ void Foam::vtkPVFoam::updateInfoPatches
} }
} }
for forAllConstIters(groups, iter)
(
HashTable<labelList, word>::const_iterator iter =
groups.begin();
iter != groups.end();
++iter
)
{ {
const word& groupName = iter.key(); const word& groupName = iter.key();
const labelList& patchIDs = iter(); const labelList& patchIDs = iter.object();
label nFaces = 0; label nFaces = 0;
forAll(patchIDs, i) forAll(patchIDs, i)

View File

@ -22,7 +22,7 @@
+ Stream output + Stream output
+ =<<= is always four characters after the start of the stream, + =<<= is always four characters after the start of the stream,
so that the =<<= symbols align, i.e. so that the =<<= symbols align, i.e.
#+begin_src c++ #+begin_src C++
Info<< ... Info<< ...
os << ... os << ...
#+end_src #+end_src
@ -215,7 +215,7 @@
*** =for= and =while= Loops *** =for= and =while= Loops
#+begin_src C++ #+begin_src C++
for (i = 0; i < maxI; i++) for (i = 0; i < maxI; ++i)
{ {
code; code;
} }
@ -226,7 +226,7 @@
( (
i = 0; i = 0;
i < maxI; i < maxI;
i++ ++i
) )
{ {
code; code;
@ -234,15 +234,22 @@
#+end_src #+end_src
*not* this (no space between =for= and =(= used) *not* this (no space between =for= and =(= used)
#+begin_src C++ #+begin_src C++
for(i = 0; i < maxI; i++) for(i = 0; i < maxI; ++i)
{ {
code; code;
} }
#+end_src #+end_src
Note that when indexing through iterators, it is often slightly more Range-base for should have a space surrounding the ':'
efficient to use the pre-increment form. Eg, =++iter= instead of =iter++= #+begin_src C++
for (auto i : range)
{
code;
}
#+end_src
Note that when indexing through iterators, it is often more efficient
to use the pre-increment form. Eg, =++iter= instead of =iter++=
*** =forAll=, =forAllIter=, =forAllConstIter=, /etc./ loops *** =forAll=, =forAllIters=, =forAllConstIters=, /etc./ loops
Like =for= loops, but Like =for= loops, but
#+begin_src C++ #+begin_src C++
forAll( forAll(
@ -251,15 +258,22 @@
#+begin_src C++ #+begin_src C++
forAll ( forAll (
#+end_src #+end_src
Using the =forAllIter= and =forAllConstIter= macros is generally In many cases, the new =forAllIters= and =forAllConstIters= macros
advantageous - less typing, easier to find later. However, since provide a good means of cycling through iterators (when a range-base
they are macros, they will fail if the iterated object contains for doesn't apply). These use the C++11 decltype and work without
any commas /e.g./ following will FAIL!: explicitly specifying the container class:
#+begin_src C++ #+begin_src C++
forAllIter(HashTable<labelPair, edge, Hash<edge>>, foo, iter) forAllIters(myEdgeHash, iter)
#+end_src
Using the older =forAllIter= and =forAllConstIter= macros will
still be seen. However, since they are macros, they will fail if
the iterated object contains any commas /e.g./ following will FAIL!:
#+begin_src C++
forAllIter(HashTable<labelPair, edge, Hash<edge>>, myEdgeHash, iter)
#+end_src #+end_src
These convenience macros are also generally avoided in other These convenience macros are also generally avoided in other
container classes and OpenFOAM primitive classes. container classes and OpenFOAM primitive classes.
In certain cases, the range-based for can also be used.
*** Splitting Over Multiple Lines *** Splitting Over Multiple Lines
***** Splitting return type and function name ***** Splitting return type and function name

View File

@ -46,10 +46,10 @@ Foam::label Foam::coupleGroupIdentifier::findOtherPatchID
<< exit(FatalError); << exit(FatalError);
} }
HashTable<labelList, word>::const_iterator fnd = HashTable<labelList>::const_iterator fnd =
pbm.groupPatchIDs().find(name()); pbm.groupPatchIDs().find(name());
if (fnd == pbm.groupPatchIDs().end()) if (!fnd.found())
{ {
if (&mesh == &thisPatch.boundaryMesh().mesh()) if (&mesh == &thisPatch.boundaryMesh().mesh())
{ {
@ -65,7 +65,7 @@ Foam::label Foam::coupleGroupIdentifier::findOtherPatchID
} }
// Mesh has patch group // Mesh has patch group
const labelList& patchIDs = fnd(); const labelList& patchIDs = fnd.object();
if (&mesh == &thisPatch.boundaryMesh().mesh()) if (&mesh == &thisPatch.boundaryMesh().mesh())
{ {

View File

@ -32,6 +32,7 @@ License
#include "lduSchedule.H" #include "lduSchedule.H"
#include "globalMeshData.H" #include "globalMeshData.H"
#include "stringListOps.H" #include "stringListOps.H"
#include "EdgeMap.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -287,7 +288,7 @@ Foam::polyBoundaryMesh::neighbourEdges() const
// From mesh edge (expressed as a point pair so as not to construct // From mesh edge (expressed as a point pair so as not to construct
// point addressing) to patch + relative edge index. // point addressing) to patch + relative edge index.
HashTable<labelPair, edge, Hash<edge>> pointsToEdge(nEdgePairs); EdgeMap<labelPair> pointsToEdge(nEdgePairs);
forAll(*this, patchi) forAll(*this, patchi)
{ {
@ -308,10 +309,9 @@ Foam::polyBoundaryMesh::neighbourEdges() const
// Edge in mesh points. // Edge in mesh points.
edge meshEdge(pp.meshPoints()[e[0]], pp.meshPoints()[e[1]]); edge meshEdge(pp.meshPoints()[e[0]], pp.meshPoints()[e[1]]);
HashTable<labelPair, edge, Hash<edge>>::iterator fnd = EdgeMap<labelPair>::iterator fnd = pointsToEdge.find(meshEdge);
pointsToEdge.find(meshEdge);
if (fnd == pointsToEdge.end()) if (!fnd.found())
{ {
// First occurrence of mesh edge. Store patch and my // First occurrence of mesh edge. Store patch and my
// local index. // local index.
@ -328,7 +328,7 @@ Foam::polyBoundaryMesh::neighbourEdges() const
else else
{ {
// Second occurrence. Store. // Second occurrence. Store.
const labelPair& edgeInfo = fnd(); const labelPair& edgeInfo = fnd.object();
neighbourEdges[patchi][edgei - pp.nInternalEdges()] = neighbourEdges[patchi][edgei - pp.nInternalEdges()] =
edgeInfo; edgeInfo;
@ -413,13 +413,13 @@ const Foam::labelList& Foam::polyBoundaryMesh::patchID() const
} }
const Foam::HashTable<Foam::labelList, Foam::word>& const Foam::HashTable<Foam::labelList>&
Foam::polyBoundaryMesh::groupPatchIDs() const Foam::polyBoundaryMesh::groupPatchIDs() const
{ {
if (!groupPatchIDsPtr_.valid()) if (!groupPatchIDsPtr_.valid())
{ {
groupPatchIDsPtr_.reset(new HashTable<labelList, word>(10)); groupPatchIDsPtr_.reset(new HashTable<labelList>(10));
HashTable<labelList, word>& groupPatchIDs = groupPatchIDsPtr_(); HashTable<labelList>& groupPatchIDs = groupPatchIDsPtr_();
const polyBoundaryMesh& bm = *this; const polyBoundaryMesh& bm = *this;
@ -431,7 +431,7 @@ Foam::polyBoundaryMesh::groupPatchIDs() const
{ {
const word& name = groups[i]; const word& name = groups[i];
HashTable<labelList, word>::iterator iter = groupPatchIDs.find HashTable<labelList>::iterator iter = groupPatchIDs.find
( (
name name
); );
@ -612,10 +612,10 @@ Foam::labelList Foam::polyBoundaryMesh::findIndices
if (usePatchGroups && groupPatchIDs().size()) if (usePatchGroups && groupPatchIDs().size())
{ {
const HashTable<labelList, word>::const_iterator iter = const HashTable<labelList>::const_iterator iter =
groupPatchIDs().find(key); groupPatchIDs().find(key);
if (iter != groupPatchIDs().end()) if (iter.found())
{ {
labelHashSet indexSet(indices); labelHashSet indexSet(indices);
@ -815,14 +815,8 @@ void Foam::polyBoundaryMesh::matchGroups
// Current set of unmatched patches // Current set of unmatched patches
nonGroupPatches = labelHashSet(patchIDs); nonGroupPatches = labelHashSet(patchIDs);
const HashTable<labelList, word>& groupPatchIDs = this->groupPatchIDs(); const HashTable<labelList>& groupPatchIDs = this->groupPatchIDs();
for forAllConstIters(groupPatchIDs, iter)
(
HashTable<labelList,word>::const_iterator iter =
groupPatchIDs.begin();
iter != groupPatchIDs.end();
++iter
)
{ {
// Store currently unmatched patches so we can restore // Store currently unmatched patches so we can restore
labelHashSet oldNonGroupPatches(nonGroupPatches); labelHashSet oldNonGroupPatches(nonGroupPatches);

View File

@ -70,7 +70,7 @@ class polyBoundaryMesh
mutable autoPtr<labelList> patchIDPtr_; mutable autoPtr<labelList> patchIDPtr_;
mutable autoPtr<HashTable<labelList, word>> groupPatchIDsPtr_; mutable autoPtr<HashTable<labelList>> groupPatchIDsPtr_;
//- Edges of neighbouring patches //- Edges of neighbouring patches
mutable autoPtr<List<labelPairList>> neighbourEdgesPtr_; mutable autoPtr<List<labelPairList>> neighbourEdgesPtr_;
@ -183,8 +183,8 @@ public:
//- Per boundary face label the patch index //- Per boundary face label the patch index
const labelList& patchID() const; const labelList& patchID() const;
//- Per patch group the patch indices //- The patch indices per patch group
const HashTable<labelList, word>& groupPatchIDs() const; const HashTable<labelList>& groupPatchIDs() const;
//- Set/add group with patches //- Set/add group with patches
void setGroup(const word& groupName, const labelList& patchIDs); void setGroup(const word& groupName, const labelList& patchIDs);

View File

@ -62,7 +62,7 @@ class hashedWordList
// Private data // Private data
//- Hash of words/indices //- Hash of words/indices
mutable HashTable<label,word> indices_; mutable HashTable<label> indices_;
// Private Member Functions // Private Member Functions
@ -141,7 +141,7 @@ public:
inline bool contains(const word& name) const; inline bool contains(const word& name) const;
//- Return the hash of words/indices for inspection //- Return the hash of words/indices for inspection
inline const HashTable<label,word>& lookup() const; inline const HashTable<label>& lookup() const;
//- Transfer the contents of the argument List into this list //- Transfer the contents of the argument List into this list
// and annul the argument list, // and annul the argument list,

View File

@ -134,7 +134,7 @@ inline void Foam::hashedWordList::append
} }
inline const Foam::HashTable<Foam::label,Foam::word>& inline const Foam::HashTable<Foam::label>&
Foam::hashedWordList::lookup() const Foam::hashedWordList::lookup() const
{ {
return indices_; return indices_;

View File

@ -869,16 +869,9 @@ void Foam::boundaryCutter::updateMesh(const mapPolyMesh& morphMap)
{ {
// Create copy since we're deleting entries // Create copy since we're deleting entries
HashTable<labelList, edge, Hash<edge>> EdgeMap<labelList> newEdgeAddedPoints(edgeAddedPoints_.size());
newEdgeAddedPoints(edgeAddedPoints_.size());
for forAllConstIters(edgeAddedPoints_, iter)
(
HashTable<labelList, edge, Hash<edge>>::const_iterator iter =
edgeAddedPoints_.begin();
iter != edgeAddedPoints_.end();
++iter
)
{ {
const edge& e = iter.key(); const edge& e = iter.key();
@ -888,7 +881,7 @@ void Foam::boundaryCutter::updateMesh(const mapPolyMesh& morphMap)
if (newStart >= 0 && newEnd >= 0) if (newStart >= 0 && newEnd >= 0)
{ {
const labelList& addedPoints = iter(); const labelList& addedPoints = iter.object();
labelList newAddedPoints(addedPoints.size()); labelList newAddedPoints(addedPoints.size());
label newI = 0; label newI = 0;

View File

@ -44,7 +44,7 @@ SourceFiles
#include "Map.H" #include "Map.H"
#include "labelList.H" #include "labelList.H"
#include "edge.H" #include "EdgeMap.H"
#include "typeInfo.H" #include "typeInfo.H"
#include "labelPair.H" #include "labelPair.H"
@ -71,7 +71,7 @@ class boundaryCutter
const polyMesh& mesh_; const polyMesh& mesh_;
//- Per edge sorted (start to end) list of points added. //- Per edge sorted (start to end) list of points added.
HashTable<labelList, edge, Hash<edge>> edgeAddedPoints_; EdgeMap<labelList> edgeAddedPoints_;
//- Per face the mid point added. //- Per face the mid point added.
Map<label> faceAddedPoint_; Map<label> faceAddedPoint_;
@ -159,8 +159,7 @@ public:
// Access // Access
//- Per edge a sorted list (start to end) of added points. //- Per edge a sorted list (start to end) of added points.
const HashTable<labelList, edge, Hash<edge>>& edgeAddedPoints() const EdgeMap<labelList>& edgeAddedPoints() const
const
{ {
return edgeAddedPoints_; return edgeAddedPoints_;
} }

View File

@ -479,13 +479,13 @@ Foam::face Foam::meshCutAndRemove::addEdgeCutsToFace(const label facei) const
// Check if edge has been cut. // Check if edge has been cut.
label fp1 = f.fcIndex(fp); label fp1 = f.fcIndex(fp);
HashTable<label, edge, Hash<edge>>::const_iterator fnd = EdgeMap<label>::const_iterator fnd =
addedPoints_.find(edge(f[fp], f[fp1])); addedPoints_.find(edge(f[fp], f[fp1]));
if (fnd != addedPoints_.end()) if (fnd.found())
{ {
// edge has been cut. Introduce new vertex. // edge has been cut. Introduce new vertex.
newFace[newFp++] = fnd(); newFace[newFp++] = fnd.object();
} }
} }
@ -541,12 +541,12 @@ Foam::face Foam::meshCutAndRemove::loopToFace
if (edgeI != -1) if (edgeI != -1)
{ {
// Existing edge. Insert split-edge point if any. // Existing edge. Insert split-edge point if any.
HashTable<label, edge, Hash<edge>>::const_iterator fnd = EdgeMap<label>::const_iterator fnd =
addedPoints_.find(mesh().edges()[edgeI]); addedPoints_.find(mesh().edges()[edgeI]);
if (fnd != addedPoints_.end()) if (fnd.found())
{ {
newFace[newFacei++] = fnd(); newFace[newFacei++] = fnd.object();
} }
} }
} }
@ -1302,24 +1302,17 @@ void Foam::meshCutAndRemove::updateMesh(const mapPolyMesh& map)
} }
{ {
HashTable<label, edge, Hash<edge>> newAddedPoints(addedPoints_.size()); EdgeMap<label> newAddedPoints(addedPoints_.size());
for forAllConstIters(addedPoints_, iter)
(
HashTable<label, edge, Hash<edge>>::const_iterator iter =
addedPoints_.begin();
iter != addedPoints_.end();
++iter
)
{ {
const edge& e = iter.key(); const edge& e = iter.key();
const label addedPointi = iter.object();
label newStart = map.reversePointMap()[e.start()]; label newStart = map.reversePointMap()[e.start()];
label newEnd = map.reversePointMap()[e.end()]; label newEnd = map.reversePointMap()[e.end()];
label addedPointi = iter();
label newAddedPointi = map.reversePointMap()[addedPointi]; label newAddedPointi = map.reversePointMap()[addedPointi];
if ((newStart >= 0) && (newEnd >= 0) && (newAddedPointi >= 0)) if ((newStart >= 0) && (newEnd >= 0) && (newAddedPointi >= 0))

View File

@ -40,6 +40,7 @@ SourceFiles
#include "labelList.H" #include "labelList.H"
#include "typeInfo.H" #include "typeInfo.H"
#include "Map.H" #include "Map.H"
#include "EdgeMap.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -70,7 +71,7 @@ class meshCutAndRemove
//- Points added in last setRefinement. Per split edge label of added //- Points added in last setRefinement. Per split edge label of added
// point // point
HashTable<label, edge, Hash<edge>> addedPoints_; EdgeMap<label> addedPoints_;
// Private Static Functions // Private Static Functions
@ -225,7 +226,7 @@ public:
//- Points added. Per split edge label of added point. //- Points added. Per split edge label of added point.
// (note: fairly useless across topology changes since one of the // (note: fairly useless across topology changes since one of the
// points of the edge will probably disappear) // points of the edge will probably disappear)
const HashTable<label, edge, Hash<edge>>& addedPoints() const const EdgeMap<label>& addedPoints() const
{ {
return addedPoints_; return addedPoints_;
} }

View File

@ -424,13 +424,13 @@ Foam::face Foam::meshCutter::addEdgeCutsToFace(const label facei) const
// Check if edge has been cut. // Check if edge has been cut.
label fp1 = f.fcIndex(fp); label fp1 = f.fcIndex(fp);
HashTable<label, edge, Hash<edge>>::const_iterator fnd = EdgeMap<label>::const_iterator fnd =
addedPoints_.find(edge(f[fp], f[fp1])); addedPoints_.find(edge(f[fp], f[fp1]));
if (fnd != addedPoints_.end()) if (fnd.found())
{ {
// edge has been cut. Introduce new vertex. // edge has been cut. Introduce new vertex.
newFace[newFp++] = fnd(); newFace[newFp++] = fnd.object();
} }
} }
@ -483,12 +483,12 @@ Foam::face Foam::meshCutter::loopToFace
if (edgeI != -1) if (edgeI != -1)
{ {
// Existing edge. Insert split-edge point if any. // Existing edge. Insert split-edge point if any.
HashTable<label, edge, Hash<edge>>::const_iterator fnd = EdgeMap<label>::const_iterator fnd =
addedPoints_.find(mesh().edges()[edgeI]); addedPoints_.find(mesh().edges()[edgeI]);
if (fnd != addedPoints_.end()) if (fnd.found())
{ {
newFace[newFacei++] = fnd(); newFace[newFacei++] = fnd.object();
} }
} }
} }
@ -1043,24 +1043,17 @@ void Foam::meshCutter::updateMesh(const mapPolyMesh& morphMap)
} }
{ {
HashTable<label, edge, Hash<edge>> newAddedPoints(addedPoints_.size()); EdgeMap<label> newAddedPoints(addedPoints_.size());
for forAllConstIters(addedPoints_, iter)
(
HashTable<label, edge, Hash<edge>>::const_iterator iter =
addedPoints_.begin();
iter != addedPoints_.end();
++iter
)
{ {
const edge& e = iter.key(); const edge& e = iter.key();
const label addedPointi = iter.object();
label newStart = morphMap.reversePointMap()[e.start()]; label newStart = morphMap.reversePointMap()[e.start()];
label newEnd = morphMap.reversePointMap()[e.end()]; label newEnd = morphMap.reversePointMap()[e.end()];
label addedPointi = iter();
label newAddedPointi = morphMap.reversePointMap()[addedPointi]; label newAddedPointi = morphMap.reversePointMap()[addedPointi];
if ((newStart >= 0) && (newEnd >= 0) && (newAddedPointi >= 0)) if ((newStart >= 0) && (newEnd >= 0) && (newAddedPointi >= 0))

View File

@ -115,6 +115,7 @@ SourceFiles
#include "labelList.H" #include "labelList.H"
#include "typeInfo.H" #include "typeInfo.H"
#include "Map.H" #include "Map.H"
#include "EdgeMap.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -148,7 +149,7 @@ class meshCutter
//- Points added in last setRefinement. Per split edge label of added //- Points added in last setRefinement. Per split edge label of added
// point // point
HashTable<label, edge, Hash<edge>> addedPoints_; EdgeMap<label> addedPoints_;
// Private Static Functions // Private Static Functions
@ -307,7 +308,7 @@ public:
} }
//- Points added. Per split edge label of added point //- Points added. Per split edge label of added point
const HashTable<label, edge, Hash<edge>>& addedPoints() const const EdgeMap<label>& addedPoints() const
{ {
return addedPoints_; return addedPoints_;
} }