From dd9ecd4988d0f7b1b000c57f44f84a6dc735b054 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 8 Aug 2018 23:54:27 +0200 Subject: [PATCH] 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, List such that the hash value for List> 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() which forwards to string::hash() anyhow --- .../multiphaseSystem/multiphaseSystem.H | 13 +- .../phasesSystem/phaseSystem/phaseSystem.H | 3 +- applications/test/FixedList/Test-FixedList.C | 7 +- applications/test/Hashing/Test-Hashing.C | 313 +++++++++++++----- applications/test/Hashing/hashingTests | 42 +++ applications/test/List/Test-List.C | 14 + .../ideasUnvToFoam/ideasUnvToFoam.C | 25 +- .../netgenNeutralToFoam/netgenNeutralToFoam.C | 9 +- .../containers/Lists/FixedList/FixedList.H | 72 +++- .../containers/Lists/FixedList/FixedListI.H | 28 -- src/OpenFOAM/containers/Lists/List/List.H | 24 ++ src/OpenFOAM/containers/Lists/UList/UList.H | 55 ++- src/OpenFOAM/containers/Lists/UList/UListI.H | 1 + src/OpenFOAM/meshes/meshShapes/edge/edge.H | 91 ++--- src/OpenFOAM/meshes/meshShapes/face/face.H | 30 +- .../meshes/meshShapes/triFace/triFace.H | 77 +++-- .../processorCyclicPolyPatch.C | 4 +- src/OpenFOAM/primitives/Pair/Pair.H | 61 +++- src/OpenFOAM/primitives/hashes/Hash/Hash.H | 92 ++--- src/OpenFOAM/primitives/hashes/Hash/HashFwd.H | 46 +++ .../primitives/hashes/Hasher/Hasher.H | 20 +- .../surface/cuttingPlane/cuttingPlane.C | 29 +- src/surfMesh/surfaceFormats/obj/OBJstream.H | 1 - 23 files changed, 712 insertions(+), 345 deletions(-) create mode 100644 src/OpenFOAM/primitives/hashes/Hash/HashFwd.H diff --git a/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/phasesSystem/phaseSystem/multiphaseSystem/multiphaseSystem.H b/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/phasesSystem/phaseSystem/multiphaseSystem/multiphaseSystem.H index 068d25961b..ef63221ac7 100644 --- a/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/phasesSystem/phaseSystem/multiphaseSystem/multiphaseSystem.H +++ b/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/phasesSystem/phaseSystem/multiphaseSystem/multiphaseSystem.H @@ -54,20 +54,13 @@ class multiphaseSystem { protected: - typedef - HashTable - < - volScalarField::Internal, - word, - word::hash - > - SuSpTable; + typedef HashTable SuSpTable; typedef HashTable scalarTable; - typedef HashTable - compressionFluxTable; + typedef HashTable compressionFluxTable; + // Protected data diff --git a/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/phasesSystem/phaseSystem/phaseSystem.H b/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/phasesSystem/phaseSystem/phaseSystem.H index ad0dc154d0..031587beeb 100644 --- a/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/phasesSystem/phaseSystem/phaseSystem.H +++ b/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/phasesSystem/phaseSystem/phaseSystem.H @@ -75,8 +75,7 @@ public: phasePairTable; - typedef - HashTable, word, word::hash> phaseModelTable; + typedef HashTable> phaseModelTable; protected: diff --git a/applications/test/FixedList/Test-FixedList.C b/applications/test/FixedList/Test-FixedList.C index 1e3703b2b8..0b5cff8374 100644 --- a/applications/test/FixedList/Test-FixedList.C +++ b/applications/test/FixedList/Test-FixedList.C @@ -139,13 +139,16 @@ int main(int argc, char *argv[]) FixedList list1{2, 3, 4, 5}; Info<< "list1:" << list1 - << " hash:" << FixedList::Hash<>()(list1) << nl; + << " hash:" << FixedList::Hash<>()(list1) << nl + << " hash:" << Hash>()(list1) << nl; label a[4] = {0, 1, 2, 3}; FixedList list2(a); Info<< "list2:" << list2 - << " hash:" << FixedList::Hash<>()(list2) << nl; + << " hash:" << FixedList::Hash<>()(list2) << nl + << " hash:" << Hash>()(list2) << nl; + // Using FixedList for content too { diff --git a/applications/test/Hashing/Test-Hashing.C b/applications/test/Hashing/Test-Hashing.C index 4461679d08..da3688481a 100644 --- a/applications/test/Hashing/Test-Hashing.C +++ b/applications/test/Hashing/Test-Hashing.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -36,6 +36,7 @@ Description #include "labelList.H" #include "labelPair.H" #include "edgeList.H" +#include "faceList.H" #include "triFaceList.H" #include "Hash.H" @@ -50,7 +51,7 @@ void infoHashString { if (modulus) { - Info<< "basic string hashing (mod " << label(modulus) << ")" << endl; + Info<< "basic string hashing (mod " << label(modulus) << ")" << nl; for (const auto& str : lst) { @@ -72,6 +73,190 @@ void infoHashString } + +void reportHashList(const UList& list) +{ + Info<< "contiguous = " << contiguous() << nl << nl; + + for (const string& val : list) + { + unsigned hash1 = string::hash()(val); + + Info<< hex << hash1 << ": " << val << nl; + } +} + + +void reportHashList(const UList