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<edge> specialization is commutative, without multiplication.
- Hash<triFace> 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).
This commit is contained in:
Mark Olesen
2009-03-04 10:50:14 +01:00
parent 44a86232af
commit 17548296be
28 changed files with 394 additions and 510 deletions

View File

@ -56,6 +56,12 @@ int main(int argc, char *argv[])
Info<< "list:" << list
<< " hash:" << FixedList<label, 4>::Hash<>()(list) << endl;
Info<< "FixedList<label, ..> is contiguous, "
"thus hashing function is irrelevant: with string::hash" << endl;
Info<< "list:" << list
<< " hash:" << FixedList<label, 4>::Hash<string::hash>()(list) << endl;
label a[4] = {0, 1, 2, 3};
FixedList<label, 4> list2(a);

View File

@ -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<label>() << " "
<< "sizeof(label) " << unsigned(sizeof(label)) << endl << endl;
Info<<"contiguous = " << contiguous<label>() << endl << endl;
labelList lst(is);
unsigned hash4 = 0;
forAll(lst, i)
{
unsigned hash1 = Hashing::intHash(lst[i]);
// direct value
unsigned hash1 = Hash<label>()(lst[i]);
unsigned hash2 = Hashing::jenkins
(
reinterpret_cast<const char*>(&lst[i]),
sizeof(label)
);
unsigned hash3 = Hashing::jenkins
(
reinterpret_cast<const unsigned*>(&lst[i]),
1
);
// incremental
hash4 = Hashing::jenkins
(
reinterpret_cast<const char*>(&lst[i]),
sizeof(label),
hash4
);
// hashed byte-wise
unsigned hash2 = Hash<label>()(lst[i], 0);
Info<< hex << hash1
<< " (alt: " << hash2 << ")"
<< " (alt: " << hash3 << ")"
<< " (incr: " << hash4 << ")"
<< " (seeded: " << hash2 << ")"
<< ": " << dec << lst[i] << endl;
}
if (contiguous<label>())
{
unsigned hash1 = Hashing::jenkins
unsigned hash3 = Hasher
(
lst.cdata(),
lst.size() * sizeof(label)
);
Info<<"contiguous hashed value " << hex << hash1 << endl;
Info<<"contiguous hashed value " << hex << hash3 << endl;
}
}
else if (listType == "labelListList")
@ -131,9 +107,9 @@ int main(int argc, char *argv[])
forAll(lst, i)
{
unsigned hash1 = Hashing::jenkins
unsigned hash1 = Hasher
(
reinterpret_cast<const char*>(lst[i].cdata()),
lst[i].cdata(),
lst[i].size() * sizeof(label)
);

View File

@ -1,6 +1,6 @@
// code taken more-or-less from Paul Hsieh's tests
#include "Hashing.H"
#include "Hasher.H"
#include <stdio.h>
#include <time.h>
@ -692,7 +692,7 @@ uint32_t hashLookup3Orig (const char * k, int length) {
}
uint32_t hashLookup3 (const char * k, int length) {
return Foam::Hashing::jenkins(k, length);
return Foam::Hasher(k, length, 0);
}