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_); index.swap(index_);
return true; return true;
} }
std::unordered_map<StringPiece, uint32_t> index_; unordered_map<StringPiece, uint32_t> index_;
}; };
int main(int argc, char** argv) { int main(int argc, char** argv) {
/*
Benchmark::Register(new BM_MPHIndexCreate("URLS100k")); Benchmark::Register(new BM_MPHIndexCreate("URLS100k"));
Benchmark::Register(new BM_STLIndexCreate("URLS100k")); Benchmark::Register(new BM_STLIndexCreate("URLS100k"));
Benchmark::Register(new BM_MPHIndexSearch("URLS100k", 100*1000*1000)); Benchmark::Register(new BM_MPHIndexSearch("URLS100k", 10*1000*1000));
Benchmark::Register(new BM_STLIndexSearch("URLS100k", 100*1000*1000)); Benchmark::Register(new BM_STLIndexSearch("URLS100k", 10*1000*1000));
*/ Benchmark::Register(new BM_CmphIndexSearch("URLS100k", 10*1000*1000));
Benchmark::Register(new BM_CmphIndexSearch("URLS100k", 100*1000*1000));
Benchmark::RunAll(); Benchmark::RunAll();
return 0; return 0;
} }

View File

@ -10,8 +10,8 @@
namespace cxxmph { namespace cxxmph {
template<class Container, class T> template<class MapType, class T>
const T* myfind(const Container& mymap, const T& k) { const T* myfind(const MapType& mymap, const T& k) {
auto it = mymap.find(k); auto it = mymap.find(k);
if (it == mymap.end()) return NULL; if (it == mymap.end()) return NULL;
return &it->second; return &it->second;
@ -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<mph_map<StringPiece, StringPiece>>("URLS100k"));
Benchmark::Register(new BM_CreateUrls<unordered_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<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<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<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_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<unordered_map<uint64_t, uint64_t>>);
Benchmark::Register(new BM_SearchUint64<mph_map<uint64_t, uint64_t>>); Benchmark::Register(new BM_SearchUint64<mph_map<uint64_t, uint64_t>>);
*/
Benchmark::RunAll(); Benchmark::RunAll();
} }

View File

@ -138,8 +138,7 @@ bool MPHIndex::Reset(ForwardIterator begin, ForwardIterator end) {
std::vector<uint32_t> queue; std::vector<uint32_t> queue;
while (1) { while (1) {
// cerr << "Iterations missing: " << iterations << endl; // 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();
// for (int i = 0; i < 3; ++i) hash_seed_[i] = random() + i;
if (Mapping<SeededHashFcn>(begin, end, &edges, &queue)) break; if (Mapping<SeededHashFcn>(begin, end, &edges, &queue)) break;
else --iterations; else --iterations;
if (iterations == 0) break; 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 { MPH_MAP_METHOD_DECL(my_int32_t, index)(const key_type& k) const {
assert(slack_.empty());
if (index_.size() == 0) return -1; if (index_.size() == 0) return -1;
return index_.index(k); 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 { struct Murmur2 {
template<class Key> template<class Key>
uint32_t operator()(const Key& k) const { 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; }; { typedef seeded_hash_function<Murmur2> hash_function; };
template <> struct seeded_hash<std::hash<unsigned short> > template <> struct seeded_hash<std::hash<unsigned short> >
{ typedef seeded_hash_function<Murmur2> hash_function; }; { typedef seeded_hash_function<Murmur2> hash_function; };
/*
template <> struct seeded_hash<std::hash<int> > template <> struct seeded_hash<std::hash<int> >
{ typedef seeded_hash_function<Murmur2> hash_function; }; { typedef seeded_hash_function<Murmur2> hash_function; };
template <> struct seeded_hash<std::hash<unsigned int> > 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; }; { typedef seeded_hash_function<Murmur2> hash_function; };
template <> struct seeded_hash<std::hash<unsigned long long> > template <> struct seeded_hash<std::hash<unsigned long long> >
{ typedef seeded_hash_function<Murmur2> hash_function; }; { typedef seeded_hash_function<Murmur2> hash_function; };
*/
} // namespace cxxmph } // namespace cxxmph