diff --git a/cxxmph/bm_map.cc b/cxxmph/bm_map.cc index 0f8dace..e24c9ee 100644 --- a/cxxmph/bm_map.cc +++ b/cxxmph/bm_map.cc @@ -72,8 +72,13 @@ class BM_SearchUint64 : public SearchUint64Benchmark { } mymap_.rehash(mymap_.bucket_count()); // Double check if everything is all right + cerr << "Doing double check" << endl; for (uint32_t i = 0; i < values_.size(); ++i) { - if (mymap_[values_[i]] != values_[i]) return false; + if (mymap_[values_[i]] != values_[i]) { + fprintf(stderr, "Looking for %u th key value %llu yielded %llu\n", + i ,values_[i], mymap_[values_[i]]); + return false; + } } return true; } @@ -95,12 +100,14 @@ using namespace cxxmph; int main(int argc, char** argv) { srandom(4); + /* Benchmark::Register(new BM_CreateUrls>("URLS100k")); Benchmark::Register(new BM_CreateUrls>("URLS100k")); Benchmark::Register(new BM_SearchUrls>("URLS100k", 10*1000 * 1000, 0)); Benchmark::Register(new BM_SearchUrls>("URLS100k", 10*1000 * 1000, 0)); Benchmark::Register(new BM_SearchUrls>("URLS100k", 10*1000 * 1000, 0.9)); Benchmark::Register(new BM_SearchUrls>("URLS100k", 10*1000 * 1000, 0.9)); + */ Benchmark::Register(new BM_SearchUint64>); Benchmark::Register(new BM_SearchUint64>); Benchmark::RunAll(); diff --git a/cxxmph/mph_map.h b/cxxmph/mph_map.h index 832f7b3..aec6ad0 100644 --- a/cxxmph/mph_map.h +++ b/cxxmph/mph_map.h @@ -79,11 +79,10 @@ class mph_map { inline const_iterator find(const key_type& k) const; typedef int32_t my_int32_t; // help macros inline int32_t index(const key_type& k) const; - inline int32_t index2(const key_type& k) const; data_type& operator[](const key_type &k); const data_type& operator[](const key_type &k) const; - size_type bucket_count() const { return index_.perfect_hash_size() + slack_.bucket_count(); } + size_type bucket_count() const { return index_.minimal_perfect_hash_size() + slack_.bucket_count(); } void rehash(size_type nbuckets /*ignored*/); protected: // mimicking STL implementation @@ -154,13 +153,13 @@ MPH_MAP_METHOD_DECL(void_type, pack)() { make_iterator_first(begin()), make_iterator_first(end()), size_); if (!success) { exit(-1); } - vector new_values(index_.perfect_hash_size()); + vector new_values(index_.minimal_perfect_hash_size()); new_values.reserve(new_values.size() * 2); - vector new_present(index_.perfect_hash_size(), false); + vector new_present(index_.minimal_perfect_hash_size(), false); new_present.reserve(new_present.size() * 2); for (iterator it = begin(), it_end = end(); it != it_end; ++it) { - size_type id = index_.perfect_hash(it->first); - assert(id < index_.perfect_hash_size()); + size_type id = index_.minimal_perfect_hash(it->first); + assert(id < index_.minimal_perfect_hash_size()); assert(id < new_values.size()); new_values[id] = *it; new_present[id] = true; @@ -211,21 +210,11 @@ MPH_MAP_INLINE_METHOD_DECL(iterator, find)(const key_type& k) { return make_solid(&values_, &present_, vit);; } -MPH_MAP_INLINE_METHOD_DECL(my_int32_t, index2)(const key_type& k) const { - if (__builtin_expect(index_.perfect_hash_size(), 1)) { - auto perfect_hash = index_.perfect_hash(k); - return perfect_hash; - } - return -1; -} - - - MPH_MAP_INLINE_METHOD_DECL(my_int32_t, index)(const key_type& k) const { - if (__builtin_expect(index_.perfect_hash_size(), 1)) { - auto perfect_hash = index_.perfect_hash(k); - if (__builtin_expect(present_[perfect_hash], true)) { - return perfect_hash; + if (__builtin_expect(index_.minimal_perfect_hash_size(), 1)) { + auto minimal_perfect_hash = index_.minimal_perfect_hash(k); + if (__builtin_expect(present_[minimal_perfect_hash], true)) { + return minimal_perfect_hash; } } if (__builtin_expect(!slack_.empty(), 0)) {