From 17548296be1dd8854c810427f3613bd1ffde8035 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 4 Mar 2009 10:50:14 +0100 Subject: [PATCH] Switched from old hashing functions to use Bob Jenkins' hash routine - If the underlying type is contiguous, FixedList hashes its storage directly. - Drop labelPairHash (non-commutative) from fvMeshDistribute since FixedList::Hash does the right thing anyhow. - Hash specialization is commutative, without multiplication. - Hash specialization kept multiplication (but now uLabel). There's not much point optimizing it, since it's not used much anyhow. Misc. changes - added StaticAssert to NamedEnum.H - label.H / uLabel.H : define FOAM_LABEL_MAX, FOAM_ULABEL_MAX with the values finally used for the storage. These can be useful for pre-processor checks elsewhere (although I stopped needing them in the meantime). --- applications/test/FixedList/FixedListTest.C | 6 + applications/test/Hashing/testHashing.C | 50 +-- .../test/HashingSpeed/testHashingSpeed.C | 4 +- src/OpenFOAM/Make/files | 2 +- .../containers/Lists/FixedList/FixedList.H | 10 +- .../containers/Lists/FixedList/FixedListI.H | 26 +- src/OpenFOAM/containers/NamedEnum/NamedEnum.H | 6 +- src/OpenFOAM/meshes/meshShapes/edge/edge.H | 29 +- .../meshes/meshShapes/triFace/triFace.H | 23 +- .../meshes/meshShapes/triFace/triFaceI.H | 2 +- src/OpenFOAM/primitives/Pair/Pair.H | 23 +- src/OpenFOAM/primitives/Scalar/Scalar.C | 10 +- src/OpenFOAM/primitives/char/charIO.C | 2 +- src/OpenFOAM/primitives/hashes/Hash/Hash.H | 51 ++- .../{Hashing/Hashing.C => Hasher/Hasher.C} | 112 +++--- .../primitives/hashes/Hasher/Hasher.H | 93 +++++ .../primitives/hashes/Hashing/Hashing.H | 321 ------------------ src/OpenFOAM/primitives/ints/label/label.C | 2 +- src/OpenFOAM/primitives/ints/label/label.H | 42 ++- src/OpenFOAM/primitives/ints/uLabel/uLabel.C | 2 +- src/OpenFOAM/primitives/ints/uLabel/uLabel.H | 32 +- src/OpenFOAM/primitives/ints/ulong/ulong.H | 2 +- src/OpenFOAM/primitives/ints/ulong/ulongIO.C | 8 +- .../primitives/strings/string/string.H | 3 +- .../primitives/strings/string/stringI.H | 14 +- .../fvMeshDistribute/fvMeshDistribute.C | 6 +- .../fvMeshDistribute/fvMeshDistribute.H | 17 - .../polyTopoChange/polyTopoChange/hexRef8.C | 6 +- 28 files changed, 394 insertions(+), 510 deletions(-) rename src/OpenFOAM/primitives/hashes/{Hashing/Hashing.C => Hasher/Hasher.C} (91%) create mode 100644 src/OpenFOAM/primitives/hashes/Hasher/Hasher.H delete mode 100644 src/OpenFOAM/primitives/hashes/Hashing/Hashing.H diff --git a/applications/test/FixedList/FixedListTest.C b/applications/test/FixedList/FixedListTest.C index d82f077eae..e46e910d3a 100644 --- a/applications/test/FixedList/FixedListTest.C +++ b/applications/test/FixedList/FixedListTest.C @@ -56,6 +56,12 @@ int main(int argc, char *argv[]) Info<< "list:" << list << " hash:" << FixedList::Hash<>()(list) << endl; + Info<< "FixedList is contiguous, " + "thus hashing function is irrelevant: with string::hash" << endl; + + Info<< "list:" << list + << " hash:" << FixedList::Hash()(list) << endl; + label a[4] = {0, 1, 2, 3}; FixedList list2(a); diff --git a/applications/test/Hashing/testHashing.C b/applications/test/Hashing/testHashing.C index 109ddf28d4..248972558c 100644 --- a/applications/test/Hashing/testHashing.C +++ b/applications/test/Hashing/testHashing.C @@ -37,7 +37,7 @@ Description #include "labelList.H" #include "labelPair.H" -#include "Hashing.H" +#include "Hash.H" using namespace Foam; @@ -65,64 +65,40 @@ int main(int argc, char *argv[]) forAll(lst, i) { - unsigned hash1 = Hashing::jenkins(lst[i]); - unsigned hash2 = string::hash()(lst[i]); + unsigned hash1 = string::hash()(lst[i]); - Info<< hex << hash1 - << " (prev " << hash2 << ")" - << ": " << lst[i] << endl; + Info<< hex << hash1 << ": " << lst[i] << endl; } } else if (listType == "labelList") { - Info<<"contiguous = " << contiguous