Merge remote-tracking branch 'origin/topic/matthias/bloom-filter' into topic/robin/bloom-filter-merge

* origin/topic/matthias/bloom-filter:
  Support UHF hashing for >= UHASH_KEY_SIZE bytes.
This commit is contained in:
Robin Sommer 2013-08-01 10:38:23 -07:00
commit 00e4369eae
4 changed files with 25 additions and 8 deletions

View file

@ -1,6 +1,7 @@
// See the file "COPYING" in the main distribution directory for copyright.
#include <typeinfo>
#include <openssl/md5.h>
#include "Hasher.h"
#include "NetVar.h"
@ -82,15 +83,30 @@ Hasher::Hasher(size_t arg_k, size_t arg_seed)
seed = arg_seed;
}
UHF::UHF(size_t seed)
: h(seed)
UHF::UHF(size_t arg_seed)
: h(arg_seed)
{
seed = arg_seed;
}
// This function is almost equivalent to HashKey::HashBytes except that it
// does not depend on global state and that we mix in the seed multiple
// times.
Hasher::digest UHF::hash(const void* x, size_t n) const
{
assert(n <= UHASH_KEY_SIZE);
return n == 0 ? 0 : h(x, n);
if ( n <= UHASH_KEY_SIZE )
return n == 0 ? 0 : h(x, n);
unsigned char d[16];
MD5(reinterpret_cast<const unsigned char*>(x), n, d);
const unsigned char* s = reinterpret_cast<const unsigned char*>(&seed);
for ( size_t i = 0; i < 16; ++i )
d[i] ^= s[i % sizeof(seed)];
MD5(d, 16, d);
return d[0];
}
DefaultHasher::DefaultHasher(size_t k, size_t seed)

View file

@ -123,9 +123,9 @@ public:
* Constructs an H3 hash function seeded with a given seed and an
* optional extra seed to replace the initial Bro seed.
*
* @param seed The seed to use for this instance.
* @param arg_seed The seed to use for this instance.
*/
UHF(size_t seed = 0);
UHF(size_t arg_seed = 0);
template <typename T>
Hasher::digest operator()(const T& x) const
@ -171,6 +171,7 @@ private:
static size_t compute_seed(size_t seed);
H3<Hasher::digest, UHASH_KEY_SIZE> h;
size_t seed;
};