From 1e1cbfe6069c3c33199b70a9a787c5c50b05dbb6 Mon Sep 17 00:00:00 2001 From: Davi de Castro Reis Date: Tue, 14 Jun 2011 03:38:23 -0300 Subject: [PATCH] Trying perfect hash. --- cxxmph/mph_index.h | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/cxxmph/mph_index.h b/cxxmph/mph_index.h index 02f7368..3083a60 100644 --- a/cxxmph/mph_index.h +++ b/cxxmph/mph_index.h @@ -35,6 +35,11 @@ class MPHIndex { uint32_t size() const { return m_; } void clear(); + uint32_t perfect_hash_size() const { return n_; } + template // must agree with Reset + uint32_t perfect_hash(const Key& x) const; + template // must agree with Reset + uint32_t minimal_perfect_hash(const Key& x) const; // Serialization machinery for mmap usage. // Serialized tables are not guaranteed to work across versions or different // endianness (although they could easily be made to be). @@ -146,7 +151,7 @@ bool MPHIndex::Mapping( } template -uint32_t MPHIndex::index(const Key& key) const { +uint32_t MPHIndex::perfect_hash(const Key& key) const { uint32_t h[3]; for (int i = 0; i < 3; ++i) h[i] = SeededHashFcn()(key, hash_seed_[i]); assert(r_); @@ -159,8 +164,16 @@ uint32_t MPHIndex::index(const Key& key) const { assert((h[1] >> 2) > 2) +uint32_t MPHIndex::minimal_perfect_hash(const Key& key) const { + return Rank(perfect_hash(key)); +} + +template +uint32_t MPHIndex::index(const Key& key) const { + return minimal_perfect_hash(key); } template >::hash_function>