1
Fork 0

Removed unnecessary seed mod which was breaking on presence of poor hash functions.

This commit is contained in:
Davi Reis 2012-03-07 01:48:20 -05:00
parent b8b0cde5c7
commit dbd4856fae
5 changed files with 27 additions and 38 deletions

View File

@ -129,17 +129,15 @@ class BM_STLIndexSearch : public SearchUrlsBenchmark {
index.swap(index_);
return true;
}
std::unordered_map<StringPiece, uint32_t> index_;
unordered_map<StringPiece, uint32_t> index_;
};
int main(int argc, char** argv) {
/*
Benchmark::Register(new BM_MPHIndexCreate("URLS100k"));
Benchmark::Register(new BM_STLIndexCreate("URLS100k"));
Benchmark::Register(new BM_MPHIndexSearch("URLS100k", 100*1000*1000));
Benchmark::Register(new BM_STLIndexSearch("URLS100k", 100*1000*1000));
*/
Benchmark::Register(new BM_CmphIndexSearch("URLS100k", 100*1000*1000));
Benchmark::Register(new BM_MPHIndexSearch("URLS100k", 10*1000*1000));
Benchmark::Register(new BM_STLIndexSearch("URLS100k", 10*1000*1000));
Benchmark::Register(new BM_CmphIndexSearch("URLS100k", 10*1000*1000));
Benchmark::RunAll();
return 0;
}

View File

@ -4,29 +4,29 @@
#include "bm_common.h"
#include "mph_map.h"
using cxxmph::mph_map;
using std::string;
using std::unordered_map;
using cxxmph::mph_map;
using std::string;
using std::unordered_map;
namespace cxxmph {
namespace cxxmph {
template<class Container, class T>
const T* myfind(const Container& mymap, const T& k) {
auto it = mymap.find(k);
if (it == mymap.end()) return NULL;
return &it->second;
}
template<class MapType, class T>
const T* myfind(const MapType& mymap, const T& k) {
auto it = mymap.find(k);
if (it == mymap.end()) return NULL;
return &it->second;
}
template <class MapType>
class BM_CreateUrls : public UrlsBenchmark {
public:
BM_CreateUrls(const string& urls_file) : UrlsBenchmark(urls_file) { }
virtual void Run() {
MapType mymap;
for (auto it = urls_.begin(); it != urls_.end(); ++it) {
mymap[*it] = *it;
}
template <class MapType>
class BM_CreateUrls : public UrlsBenchmark {
public:
BM_CreateUrls(const string& urls_file) : UrlsBenchmark(urls_file) { }
virtual void Run() {
MapType mymap;
for (auto it = urls_.begin(); it != urls_.end(); ++it) {
mymap[*it] = *it;
}
}
};
template <class MapType>
@ -90,14 +90,12 @@ int main(int argc, char** argv) {
/*
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, Murmur2StringPiece>>("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, Murmur2StringPiece>>("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();
}

View File

@ -138,8 +138,7 @@ bool MPHIndex::Reset(ForwardIterator begin, ForwardIterator end) {
std::vector<uint32_t> queue;
while (1) {
// cerr << "Iterations missing: " << iterations << endl;
for (int i = 0; i < 3; ++i) hash_seed_[i] = random() % m_;
// for (int i = 0; i < 3; ++i) hash_seed_[i] = random() + i;
for (int i = 0; i < 3; ++i) hash_seed_[i] = random();
if (Mapping<SeededHashFcn>(begin, end, &edges, &queue)) break;
else --iterations;
if (iterations == 0) break;

View File

@ -186,7 +186,6 @@ MPH_MAP_METHOD_DECL(iterator, find)(const key_type& k) {
}
MPH_MAP_METHOD_DECL(my_int32_t, index)(const key_type& k) const {
assert(slack_.empty());
if (index_.size() == 0) return -1;
return index_.index(k);
}

View File

@ -19,13 +19,6 @@ struct seeded_hash_function {
}
};
struct seeded_identity_function {
template <class Key>
uint32_t operator()(const Key& k, uint32_t seed) const {
return k ^ seed;
}
};
struct Murmur2 {
template<class Key>
uint32_t operator()(const Key& k) const {
@ -78,6 +71,7 @@ template <> struct seeded_hash<std::hash<short> >
{ typedef seeded_hash_function<Murmur2> hash_function; };
template <> struct seeded_hash<std::hash<unsigned short> >
{ typedef seeded_hash_function<Murmur2> hash_function; };
/*
template <> struct seeded_hash<std::hash<int> >
{ typedef seeded_hash_function<Murmur2> hash_function; };
template <> struct seeded_hash<std::hash<unsigned int> >
@ -90,6 +84,7 @@ template <> struct seeded_hash<std::hash<long long> >
{ typedef seeded_hash_function<Murmur2> hash_function; };
template <> struct seeded_hash<std::hash<unsigned long long> >
{ typedef seeded_hash_function<Murmur2> hash_function; };
*/
} // namespace cxxmph