diff --git a/cxxmph/bm_common.h b/cxxmph/bm_common.h index eed12df..8412f98 100644 --- a/cxxmph/bm_common.h +++ b/cxxmph/bm_common.h @@ -25,6 +25,7 @@ namespace cxxmph { class UrlsBenchmark : public Benchmark { public: UrlsBenchmark(const std::string& urls_file) : urls_file_(urls_file) { } + virtual ~UrlsBenchmark() {} protected: virtual bool SetUp(); const std::string urls_file_; @@ -35,6 +36,7 @@ class SearchUrlsBenchmark : public UrlsBenchmark { public: SearchUrlsBenchmark(const std::string& urls_file, uint32_t nsearches, float miss_ratio) : UrlsBenchmark(urls_file), nsearches_(nsearches), miss_ratio_(miss_ratio) {} + virtual ~SearchUrlsBenchmark() {} protected: virtual bool SetUp(); const uint32_t nsearches_; diff --git a/cxxmph/bm_map.cc b/cxxmph/bm_map.cc index 1708c06..d5d34a8 100644 --- a/cxxmph/bm_map.cc +++ b/cxxmph/bm_map.cc @@ -13,7 +13,8 @@ using std::unordered_map; namespace cxxmph { -template + +template const T* myfind(const MapType& mymap, const T& k) { auto it = mymap.find(k); auto end = mymap.end(); @@ -38,6 +39,7 @@ class BM_SearchUrls : public SearchUrlsBenchmark { public: BM_SearchUrls(const std::string& urls_file, int nsearches, float miss_ratio) : SearchUrlsBenchmark(urls_file, nsearches, miss_ratio) { } + virtual ~BM_SearchUrls() {} virtual void Run() { for (auto it = random_.begin(); it != random_.end(); ++it) { auto v = myfind(mymap_, *it); diff --git a/cxxmph/mph_map.h b/cxxmph/mph_map.h index a844997..7b3160d 100644 --- a/cxxmph/mph_map.h +++ b/cxxmph/mph_map.h @@ -23,7 +23,6 @@ #include "mph_bits.h" #include "mph_index.h" -#include "hollow_iterator.h" namespace cxxmph { @@ -52,8 +51,8 @@ class mph_map { typedef typename std::vector::size_type size_type; typedef typename std::vector::difference_type difference_type; - typedef hollow_iterator> iterator; - typedef hollow_const_iterator> const_iterator; + typedef typename std::vector::iterator iterator; + typedef typename std::vector::const_iterator const_iterator; // For making macros simpler. typedef void void_type; @@ -100,13 +99,6 @@ class mph_map { return iterator_first(it); } - iterator make_iterator(typename std::vector::iterator it) { - return hollow_iterator>(&values_, &present_, it); - } - const_iterator make_iterator(typename std::vector::const_iterator it) const { - return hollow_const_iterator>(&values_, &present_, it); - } - void pack(); std::vector values_; std::vector present_; @@ -175,10 +167,10 @@ MPH_MAP_METHOD_DECL(void_type, pack)() { slack_type().swap(slack_); } -MPH_MAP_METHOD_DECL(iterator, begin)() { return make_iterator(values_.begin()); } -MPH_MAP_METHOD_DECL(iterator, end)() { return make_iterator(values_.end()); } -MPH_MAP_METHOD_DECL(const_iterator, begin)() const { return make_iterator(values_.begin()); } -MPH_MAP_METHOD_DECL(const_iterator, end)() const { return make_iterator(values_.end()); } +MPH_MAP_METHOD_DECL(iterator, begin)() { return values_.begin(); } +MPH_MAP_METHOD_DECL(iterator, end)() { return values_.end(); } +MPH_MAP_METHOD_DECL(const_iterator, begin)() const { return values_.begin(); } +MPH_MAP_METHOD_DECL(const_iterator, end)() const { return values_.end(); } MPH_MAP_METHOD_DECL(bool_type, empty)() const { return size_ == 0; } MPH_MAP_METHOD_DECL(size_type, size)() const { return size_; } @@ -202,38 +194,31 @@ MPH_MAP_METHOD_DECL(void_type, erase)(const key_type& k) { } MPH_MAP_METHOD_DECL(const_iterator, find)(const key_type& k) const { - 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)) { - auto vit = values_.begin() + minimal_perfect_hash; - if (equal_(k, vit->first)) return make_iterator(vit); - } - } - if (__builtin_expect(!slack_.empty(), 0)) { - auto sit = slack_.find(hasher128_.hash128(k, 0)); - if (sit != slack_.end()) return make_iterator(values_.begin() + sit->second); - } - return end(); + auto idx = index(k); + auto it = begin() + idx; + if (idx == -1 || it->first != k) return end(); + return it; } MPH_MAP_METHOD_DECL(iterator, find)(const key_type& k) { - 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)) { - auto vit = values_.begin() + minimal_perfect_hash; - if (equal_(k, vit->first)) return make_iterator(vit); - } - } - if (__builtin_expect(!slack_.empty(), 0)) { - auto sit = slack_.find(hasher128_.hash128(k, 0)); - if (sit != slack_.end()) return make_iterator(values_.begin() + sit->second); - } - return end(); + auto idx = index(k); + auto it = begin() + idx; + if (idx == -1 || it->first != k) return end(); + return it; } MPH_MAP_METHOD_DECL(my_int32_t, index)(const key_type& k) const { - if (index_.size() == 0) return -1; - return index_.minimal_perfect_hash(k); + if (__builtin_expect(!slack_.empty(), 0)) { + auto sit = slack_.find(hasher128_.hash128(k, 0)); + if (sit != slack_.end()) return sit->second; + } + 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; + } + } + return -1; } MPH_MAP_METHOD_DECL(data_type&, operator[])(const key_type& k) {