Commit 51b4c389 authored by Mark Olesen's avatar Mark Olesen
Browse files

STYLE: explicitly use iterator object() in ListOps

STYLE: adjust parameter names and template types in invertManyToMany

- more explicit about the acceptable list types
parent c4caef3a
......@@ -171,17 +171,26 @@ labelList invert(const label len, const labelUList& map);
labelListList invertOneToMany(const label len, const labelUList& map);
//- Invert many-to-many.
// Input and output types need to be inherited from List.
// eg, faces to pointFaces.
template<class InList, class OutList>
void invertManyToMany(const label len, const UList<InList>&, List<OutList>&);
// Input and output types must be inherited from List and also
// contain ints/labels. Used, for example, for faces to pointFaces.
template<class InputIntListType, class OutputIntListType>
void invertManyToMany
(
const label len,
const UList<InputIntListType>& input,
List<OutputIntListType>& output
);
template<class InList, class OutList>
List<OutList> invertManyToMany(const label len, const UList<InList>& in)
template<class InputIntListType, class OutputIntListType>
List<OutputIntListType> invertManyToMany
(
const label len,
const UList<InputIntListType>& input
)
{
List<OutList> out;
invertManyToMany<InList,OutList>(len, in, out);
return out;
List<OutputIntListType> output;
invertManyToMany<InputIntListType,OutputIntListType>(len, input, output);
return output;
}
//- Create identity map of the given length with (map[i] == i)
......
......@@ -124,16 +124,11 @@ void Foam::inplaceMapValue
Container& lst
)
{
for
(
typename Container::iterator iter = lst.begin();
iter != lst.end();
++iter
)
for (auto iter = lst.begin(); iter != lst.end(); ++iter)
{
if (iter() >= 0)
if (iter.object() >= 0)
{
iter() = oldToNew[iter()];
iter.object() = oldToNew[iter.object()];
}
}
}
......@@ -148,16 +143,11 @@ void Foam::inplaceMapKey
{
Container newLst(lst.size());
for
(
typename Container::iterator iter = lst.begin();
iter != lst.end();
++iter
)
for (auto iter = lst.begin(); iter != lst.end(); ++iter)
{
if (iter.key() >= 0)
{
newLst.insert(oldToNew[iter.key()], iter());
newLst.insert(oldToNew[iter.key()], iter.object());
}
}
......@@ -477,46 +467,45 @@ void Foam::inplaceSubsetList
}
template<class InList, class OutList>
template<class InputIntListType, class OutputIntListType>
void Foam::invertManyToMany
(
const label nEdges,
const UList<InList>& pointEdges,
List<OutList>& edges
const label len,
const UList<InputIntListType>& input,
List<OutputIntListType>& output
)
{
// Number of points per edge
labelList nPointsPerEdge(nEdges, 0);
// The output list sizes
labelList sizes(len, 0);
forAll(pointEdges, pointi)
forAll(input, listi)
{
const InList& pEdges = pointEdges[pointi];
const InputIntListType& sublist = input[listi];
forAll(pEdges, j)
forAll(sublist, idx)
{
nPointsPerEdge[pEdges[j]]++;
sizes[sublist[idx]]++;
}
}
// Size edges
edges.setSize(nEdges);
forAll(nPointsPerEdge, edgeI)
// Size output
output.setSize(len);
forAll(sizes, outi)
{
edges[edgeI].setSize(nPointsPerEdge[edgeI]);
output[outi].setSize(sizes[outi]);
}
nPointsPerEdge = 0;
// Fill edges
forAll(pointEdges, pointi)
// Fill output
sizes = 0;
forAll(input, listi)
{
const InList& pEdges = pointEdges[pointi];
const InputIntListType& sublist = input[listi];
forAll(pEdges, j)
forAll(sublist, idx)
{
label edgeI = pEdges[j];
const label outi = sublist[idx];
edges[edgeI][nPointsPerEdge[edgeI]++] = pointi;
output[outi][sizes[outi]++] = listi;
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment