From 44a86232aff12349a6842d04b55d9dbde4df025c Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 2 Mar 2009 19:57:17 +0100 Subject: [PATCH] Added Jenkin's hash functions in C++ form - not much speed difference between SuperFastHash and Jenkin's lookup3 but both are 5-10% faster than what is currently implemented in Foam::string, albeit inlining probably helps there. - TODO: integration with existing infrastructure --- applications/test/Hashing/Make/files | 3 + applications/test/Hashing/Make/options | 0 applications/test/Hashing/hashingTests | 40 + applications/test/Hashing/testHashing.C | 151 +++ applications/test/HashingSpeed/Make/files | 3 + applications/test/HashingSpeed/Make/options | 0 .../test/HashingSpeed/testHashingSpeed.C | 1070 +++++++++++++++++ src/OpenFOAM/Make/files | 2 + .../primitives/hashes/Hashing/Hashing.C | 581 +++++++++ .../primitives/hashes/Hashing/Hashing.H | 321 +++++ src/OpenFOAM/primitives/hashes/SHA1/SHA1.H | 22 +- 11 files changed, 2182 insertions(+), 11 deletions(-) create mode 100644 applications/test/Hashing/Make/files create mode 100644 applications/test/Hashing/Make/options create mode 100644 applications/test/Hashing/hashingTests create mode 100644 applications/test/Hashing/testHashing.C create mode 100644 applications/test/HashingSpeed/Make/files create mode 100644 applications/test/HashingSpeed/Make/options create mode 100644 applications/test/HashingSpeed/testHashingSpeed.C create mode 100644 src/OpenFOAM/primitives/hashes/Hashing/Hashing.C create mode 100644 src/OpenFOAM/primitives/hashes/Hashing/Hashing.H diff --git a/applications/test/Hashing/Make/files b/applications/test/Hashing/Make/files new file mode 100644 index 0000000000..a5f1087728 --- /dev/null +++ b/applications/test/Hashing/Make/files @@ -0,0 +1,3 @@ +testHashing.C + +EXE = $(FOAM_USER_APPBIN)/testHashing diff --git a/applications/test/Hashing/Make/options b/applications/test/Hashing/Make/options new file mode 100644 index 0000000000..e69de29bb2 diff --git a/applications/test/Hashing/hashingTests b/applications/test/Hashing/hashingTests new file mode 100644 index 0000000000..7c549ffa0f --- /dev/null +++ b/applications/test/Hashing/hashingTests @@ -0,0 +1,40 @@ +/*-------------------------------*- C++ -*---------------------------------*\ +| ========= | +| \\ / OpenFOAM | +| \\ / | +| \\ / The Open Source CFD Toolbox | +| \\/ http://www.OpenFOAM.org | +\*-------------------------------------------------------------------------*/ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +stringList +( + "The quick brown fox jumps over the lazy dog" + "The best hash is the one you don't write yourself!" +) + + +labelList +( + 0 + 1 + 100 + 1000 + -1 + -10 + -100 +) + +labelListList +( + (0) + (0 0) + (0 0 0) + (0 1) + (100 1000) + (0 1 100 1000) +) + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/applications/test/Hashing/testHashing.C b/applications/test/Hashing/testHashing.C new file mode 100644 index 0000000000..109ddf28d4 --- /dev/null +++ b/applications/test/Hashing/testHashing.C @@ -0,0 +1,151 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Application + testHashing + +Description + +\*---------------------------------------------------------------------------*/ + +#include "IOstreams.H" +#include "IOobject.H" +#include "IFstream.H" + +#include "stringList.H" +#include "labelList.H" +#include "labelPair.H" + +#include "Hashing.H" + +using namespace Foam; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// Main program: + +int main(int argc, char *argv[]) +{ + IFstream is("hashingTests"); + + + while (is.good()) + { + const word listType(is); + + Info<< endl; + IOobject::writeDivider(Info); + Info<< listType << endl; + + if (listType == "stringList") + { + Info<< "contiguous = " << contiguous() << endl << endl; + + stringList lst(is); + + forAll(lst, i) + { + unsigned hash1 = Hashing::jenkins(lst[i]); + unsigned hash2 = string::hash()(lst[i]); + + Info<< hex << hash1 + << " (prev " << hash2 << ")" + << ": " << lst[i] << endl; + } + + } + else if (listType == "labelList") + { + Info<<"contiguous = " << contiguous