Strange optimizations for 64 bit integers.
This commit is contained in:
parent
7b8b3e5834
commit
aa5fa26b49
|
@ -88,12 +88,14 @@ using namespace cxxmph;
|
|||
|
||||
int main(int argc, char** argv) {
|
||||
srandom(4);
|
||||
/*
|
||||
Benchmark::Register(new BM_CreateUrls<mph_map<StringPiece, StringPiece>>("URLS100k"));
|
||||
Benchmark::Register(new BM_CreateUrls<unordered_map<StringPiece, StringPiece>>("URLS100k"));
|
||||
Benchmark::Register(new BM_SearchUrls<mph_map<StringPiece, StringPiece>>("URLS100k", 10*1000 * 1000, 0));
|
||||
Benchmark::Register(new BM_SearchUrls<unordered_map<StringPiece, StringPiece, Murmur3StringPiece>>("URLS100k", 10*1000 * 1000, 0));
|
||||
Benchmark::Register(new BM_SearchUrls<mph_map<StringPiece, StringPiece>>("URLS100k", 10*1000 * 1000, 0.9));
|
||||
Benchmark::Register(new BM_SearchUrls<unordered_map<StringPiece, StringPiece, Murmur3StringPiece>>("URLS100k", 10*1000 * 1000, 0.9));
|
||||
*/
|
||||
Benchmark::Register(new BM_SearchUint64<unordered_map<uint64_t, uint64_t>>);
|
||||
Benchmark::Register(new BM_SearchUint64<mph_map<uint64_t, uint64_t>>);
|
||||
Benchmark::RunAll();
|
||||
|
|
|
@ -9,8 +9,9 @@
|
|||
#include "MurmurHash3.h"
|
||||
#include "stringpiece.h"
|
||||
|
||||
// From murmur, only used naively to extend 32 bits functions to 64 bits.
|
||||
// From murmur, only used naively to extend 32 bits functions to 128 bits.
|
||||
uint32_t fmix ( uint32_t h );
|
||||
uint64_t fmix ( uint64_t h );
|
||||
|
||||
namespace cxxmph {
|
||||
|
||||
|
@ -57,6 +58,19 @@ struct Murmur3StringPiece {
|
|||
}
|
||||
};
|
||||
|
||||
struct Murmur3Fmix64bitsType {
|
||||
template <class Key>
|
||||
uint32_t operator()(const Key& k) const {
|
||||
return fmix(*reinterpret_cast<const uint64_t*>(&k));
|
||||
}
|
||||
template <class Key>
|
||||
void hash64(const Key& k, uint32_t* out) const {
|
||||
uint64_t h = fmix(*reinterpret_cast<uint64_t*>(&k));
|
||||
*reinterpret_cast<uint64_t*>(out) = h;
|
||||
*reinterpret_cast<uint64_t*>(out + 2) = h;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct seeded_hash_function<Murmur3> {
|
||||
template <class Key>
|
||||
|
@ -87,6 +101,20 @@ struct seeded_hash_function<Murmur3StringPiece> {
|
|||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct seeded_hash_function<Murmur3Fmix64bitsType> {
|
||||
template <class Key>
|
||||
uint32_t operator()(const Key& k, uint32_t seed) const {
|
||||
return fmix(k + seed);
|
||||
}
|
||||
template <class Key>
|
||||
void hash64(const Key& k, uint32_t seed, uint32_t* out) const {
|
||||
*reinterpret_cast<uint64_t*>(out) = fmix(k ^ seed);
|
||||
*(out + 2) = fmix(*out);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <class HashFcn> struct seeded_hash
|
||||
{ typedef seeded_hash_function<HashFcn> hash_function; };
|
||||
// Use Murmur3 instead for all types defined in std::hash, plus
|
||||
|
@ -117,9 +145,9 @@ template <> struct seeded_hash<std::hash<long> >
|
|||
template <> struct seeded_hash<std::hash<unsigned long> >
|
||||
{ typedef seeded_hash_function<Murmur3> hash_function; };
|
||||
template <> struct seeded_hash<std::hash<long long> >
|
||||
{ typedef seeded_hash_function<Murmur3> hash_function; };
|
||||
{ typedef seeded_hash_function<Murmur3Fmix64bitsType> hash_function; };
|
||||
template <> struct seeded_hash<std::hash<unsigned long long> >
|
||||
{ typedef seeded_hash_function<Murmur3> hash_function; };
|
||||
{ typedef seeded_hash_function<Murmur3Fmix64bitsType> hash_function; };
|
||||
|
||||
} // namespace cxxmph
|
||||
|
||||
|
|
Loading…
Reference in New Issue