diff --git a/cxxmph/map_tester.h b/cxxmph/map_tester.h index 8b08523..10d4357 100644 --- a/cxxmph/map_tester.h +++ b/cxxmph/map_tester.h @@ -104,7 +104,7 @@ struct MapTester { if (static_cast(m.size()) != i) return false; } return true; - } + } static bool erase_value() { map_type m; int nkeys = 10 * 1000; diff --git a/cxxmph/mph_index.h b/cxxmph/mph_index.h index a99ec1e..9ab645c 100644 --- a/cxxmph/mph_index.h +++ b/cxxmph/mph_index.h @@ -252,7 +252,7 @@ struct FlexibleMPHIndex : public SimpleMPHIndex { FlexibleMPHIndex() : SimpleMPHIndex(false) {} uint32_t index(const Key& key) const { - return MPHIndex::index(key); } + return MPHIndex::perfect_hash(key); } uint32_t size() const { return MPHIndex::perfect_hash_size(); } }; // From a trade-off perspective this case does not make much sense. diff --git a/cxxmph/seeded_hash.h b/cxxmph/seeded_hash.h index e5e078d..1204b6f 100644 --- a/cxxmph/seeded_hash.h +++ b/cxxmph/seeded_hash.h @@ -10,11 +10,6 @@ #include "MurmurHash3.h" #include "stringpiece.h" -// From murmur, only used naively to extend 32 bits functions to 128 bits. -uint32_t fmix ( uint32_t h ); -// Used for a quick and dirty hash function for integers. Probably a bad idea. -uint64_t fmix ( uint64_t h ); - namespace cxxmph { struct h128 { @@ -33,15 +28,16 @@ template struct seeded_hash_function { template uint32_t operator()(const Key& k, uint32_t seed) const { - return HashFcn()(k) ^ seed; + uint32_t h; + uint32_t h0 = HashFcn()(k); + MurmurHash3_x86_32(reinterpret_cast(&h0), 4, seed, &h); + return h; } template h128 hash128(const Key& k, uint32_t seed) const { h128 h; - for (int i = 0; i < 4; ++i) { - h.uint32[i] = HashFcn()(k) ^ seed; - seed = fmix(seed); - } + uint32_t h0 = HashFcn()(k); + MurmurHash3_x64_128(reinterpret_cast(&h0), 4, seed, &h); return h; } }; @@ -78,20 +74,6 @@ struct Murmur3StringPiece { } }; -struct Murmur3Fmix64bitsType { - template - uint32_t operator()(const Key& k) const { - return fmix(*reinterpret_cast(&k)); - } - template - h128 hash128(const Key& k) const { - h128 h; - h.set64(fmix(k), 0); - h.set64(fmix(h.get64(0)), 1); - return h; - } -}; - template <> struct seeded_hash_function { template @@ -126,22 +108,6 @@ struct seeded_hash_function { } }; -template <> -struct seeded_hash_function { - template - uint32_t operator()(const Key& k, uint32_t seed) const { - return fmix(k + seed); - } - template - h128 hash128(const Key& k, uint32_t seed) const { - h128 h; - h.set64(fmix(k ^ seed), 0); - h.set64(fmix(h.get64(0)), 1); - return h; - } -}; - - template struct seeded_hash { typedef seeded_hash_function hash_function; }; // Use Murmur3 instead for all types defined in std::hash, plus diff --git a/cxxmph/seeded_hash_test.cc b/cxxmph/seeded_hash_test.cc index e5f1268..a8bef88 100644 --- a/cxxmph/seeded_hash_test.cc +++ b/cxxmph/seeded_hash_test.cc @@ -21,7 +21,7 @@ int main(int argc, char** argv) { exit(-1); } - unordered_map g; + unordered_map g; for (int i = 0; i < 1000; ++i) g[i] = i; for (int i = 0; i < 1000; ++i) if (g[i] != i) exit(-1);