ENH: add missing Hash function for List/UList (issue #966)

- there were previously no hashing mechanisms for lists so they
  would fall back to the definition for primitives and hash the
  memory location of the allocated List object.

- provide a UList::Hash<> sub-class for inheritance, and also a global
  specialization for UList<T>, List<T> such that the hash value for
  List<List<T>> cascades properly.

- provide similar function in triFace to ensure that it remains
  similar in behaviour to face.

- added SymmHash to Pair, for use when order is unimportant.

STYLE: use string::hash() more consistently

- no particular reason to use Hash<word>() which forwards to
  string::hash() anyhow
This commit is contained in:
Mark Olesen
2018-08-08 23:54:27 +02:00
parent 82bad81d79
commit dd9ecd4988
23 changed files with 712 additions and 345 deletions

View File

@ -26,9 +26,8 @@ License
#include "cuttingPlane.H"
#include "fvMesh.H"
#include "volFields.H"
#include "linePointRef.H"
#include "meshTools.H"
#include "EdgeMap.H"
#include "edgeHashes.H"
#include "HashOps.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -80,29 +79,8 @@ namespace Foam
}
//- Hash specialization for labelList. Hash incrementally.
template<>
inline unsigned Hash<labelList>::operator()
(
const labelList& list,
unsigned seed
) const
{
return Hasher(list.cdata(), list.size()*sizeof(label), seed);
}
//- Hash specialization for labelList
template<>
inline unsigned Hash<labelList>::operator()
(
const labelList& list
) const
{
return Hash<labelList>()(list, 0);
}
//- For hashing face point labels, which are pre-sorted.
typedef HashSet<labelList, Hash<labelList>> labelListHashSet;
typedef HashSet<labelList, labelList::Hash<>> labelListHashSet;
} // End namespace Foam
@ -354,6 +332,7 @@ void Foam::cuttingPlane::walkCellCuts
{
edge e(f.faceEdge(fp));
// Action #1: detect edge intersection and orient edge
if (!intersectEdgeOrient(sides, e))
{
continue;
@ -388,6 +367,7 @@ void Foam::cuttingPlane::walkCellCuts
const point& p0 = points[e[0]];
const point& p1 = points[e[1]];
// Action #2: edge cut alpha
const scalar alpha =
this->lineIntersect(linePointRef(p0, p1));
@ -540,6 +520,7 @@ void Foam::cuttingPlane::walkCellCuts
face f(localFaceLoop);
// Action #3: orient face
// Orient face to point in the same direction as the plane normal
if ((f.areaNormal(dynCutPoints) & this->normal()) < 0)
{