Fixed inline crazyness.
This commit is contained in:
parent
e85d7cc8d9
commit
bcf4962604
@ -25,6 +25,7 @@ namespace cxxmph {
|
|||||||
class UrlsBenchmark : public Benchmark {
|
class UrlsBenchmark : public Benchmark {
|
||||||
public:
|
public:
|
||||||
UrlsBenchmark(const std::string& urls_file) : urls_file_(urls_file) { }
|
UrlsBenchmark(const std::string& urls_file) : urls_file_(urls_file) { }
|
||||||
|
virtual ~UrlsBenchmark() {}
|
||||||
protected:
|
protected:
|
||||||
virtual bool SetUp();
|
virtual bool SetUp();
|
||||||
const std::string urls_file_;
|
const std::string urls_file_;
|
||||||
@ -35,6 +36,7 @@ class SearchUrlsBenchmark : public UrlsBenchmark {
|
|||||||
public:
|
public:
|
||||||
SearchUrlsBenchmark(const std::string& urls_file, uint32_t nsearches, float miss_ratio)
|
SearchUrlsBenchmark(const std::string& urls_file, uint32_t nsearches, float miss_ratio)
|
||||||
: UrlsBenchmark(urls_file), nsearches_(nsearches), miss_ratio_(miss_ratio) {}
|
: UrlsBenchmark(urls_file), nsearches_(nsearches), miss_ratio_(miss_ratio) {}
|
||||||
|
virtual ~SearchUrlsBenchmark() {}
|
||||||
protected:
|
protected:
|
||||||
virtual bool SetUp();
|
virtual bool SetUp();
|
||||||
const uint32_t nsearches_;
|
const uint32_t nsearches_;
|
||||||
|
@ -13,7 +13,8 @@ using std::unordered_map;
|
|||||||
|
|
||||||
namespace cxxmph {
|
namespace cxxmph {
|
||||||
|
|
||||||
template<class MapType, class T>
|
|
||||||
|
template <class MapType, class T>
|
||||||
const T* myfind(const MapType& mymap, const T& k) {
|
const T* myfind(const MapType& mymap, const T& k) {
|
||||||
auto it = mymap.find(k);
|
auto it = mymap.find(k);
|
||||||
auto end = mymap.end();
|
auto end = mymap.end();
|
||||||
@ -38,6 +39,7 @@ class BM_SearchUrls : public SearchUrlsBenchmark {
|
|||||||
public:
|
public:
|
||||||
BM_SearchUrls(const std::string& urls_file, int nsearches, float miss_ratio)
|
BM_SearchUrls(const std::string& urls_file, int nsearches, float miss_ratio)
|
||||||
: SearchUrlsBenchmark(urls_file, nsearches, miss_ratio) { }
|
: SearchUrlsBenchmark(urls_file, nsearches, miss_ratio) { }
|
||||||
|
virtual ~BM_SearchUrls() {}
|
||||||
virtual void Run() {
|
virtual void Run() {
|
||||||
for (auto it = random_.begin(); it != random_.end(); ++it) {
|
for (auto it = random_.begin(); it != random_.end(); ++it) {
|
||||||
auto v = myfind(mymap_, *it);
|
auto v = myfind(mymap_, *it);
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
#include "mph_bits.h"
|
#include "mph_bits.h"
|
||||||
#include "mph_index.h"
|
#include "mph_index.h"
|
||||||
#include "hollow_iterator.h"
|
|
||||||
|
|
||||||
namespace cxxmph {
|
namespace cxxmph {
|
||||||
|
|
||||||
@ -52,8 +51,8 @@ class mph_map {
|
|||||||
typedef typename std::vector<value_type>::size_type size_type;
|
typedef typename std::vector<value_type>::size_type size_type;
|
||||||
typedef typename std::vector<value_type>::difference_type difference_type;
|
typedef typename std::vector<value_type>::difference_type difference_type;
|
||||||
|
|
||||||
typedef hollow_iterator<std::vector<value_type>> iterator;
|
typedef typename std::vector<value_type>::iterator iterator;
|
||||||
typedef hollow_const_iterator<std::vector<value_type>> const_iterator;
|
typedef typename std::vector<value_type>::const_iterator const_iterator;
|
||||||
|
|
||||||
// For making macros simpler.
|
// For making macros simpler.
|
||||||
typedef void void_type;
|
typedef void void_type;
|
||||||
@ -100,13 +99,6 @@ class mph_map {
|
|||||||
return iterator_first<iterator>(it);
|
return iterator_first<iterator>(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
iterator make_iterator(typename std::vector<value_type>::iterator it) {
|
|
||||||
return hollow_iterator<std::vector<value_type>>(&values_, &present_, it);
|
|
||||||
}
|
|
||||||
const_iterator make_iterator(typename std::vector<value_type>::const_iterator it) const {
|
|
||||||
return hollow_const_iterator<std::vector<value_type>>(&values_, &present_, it);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pack();
|
void pack();
|
||||||
std::vector<value_type> values_;
|
std::vector<value_type> values_;
|
||||||
std::vector<bool> present_;
|
std::vector<bool> present_;
|
||||||
@ -175,10 +167,10 @@ MPH_MAP_METHOD_DECL(void_type, pack)() {
|
|||||||
slack_type().swap(slack_);
|
slack_type().swap(slack_);
|
||||||
}
|
}
|
||||||
|
|
||||||
MPH_MAP_METHOD_DECL(iterator, begin)() { return make_iterator(values_.begin()); }
|
MPH_MAP_METHOD_DECL(iterator, begin)() { return values_.begin(); }
|
||||||
MPH_MAP_METHOD_DECL(iterator, end)() { return make_iterator(values_.end()); }
|
MPH_MAP_METHOD_DECL(iterator, end)() { return values_.end(); }
|
||||||
MPH_MAP_METHOD_DECL(const_iterator, begin)() const { return make_iterator(values_.begin()); }
|
MPH_MAP_METHOD_DECL(const_iterator, begin)() const { return values_.begin(); }
|
||||||
MPH_MAP_METHOD_DECL(const_iterator, end)() const { return make_iterator(values_.end()); }
|
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(bool_type, empty)() const { return size_ == 0; }
|
||||||
MPH_MAP_METHOD_DECL(size_type, size)() const { return size_; }
|
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 {
|
MPH_MAP_METHOD_DECL(const_iterator, find)(const key_type& k) const {
|
||||||
if (__builtin_expect(index_.minimal_perfect_hash_size(), 1)) {
|
auto idx = index(k);
|
||||||
auto minimal_perfect_hash = index_.minimal_perfect_hash(k);
|
auto it = begin() + idx;
|
||||||
if (__builtin_expect(present_[minimal_perfect_hash], true)) {
|
if (idx == -1 || it->first != k) return end();
|
||||||
auto vit = values_.begin() + minimal_perfect_hash;
|
return it;
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MPH_MAP_METHOD_DECL(iterator, find)(const key_type& k) {
|
MPH_MAP_METHOD_DECL(iterator, find)(const key_type& k) {
|
||||||
if (__builtin_expect(index_.minimal_perfect_hash_size(), 1)) {
|
auto idx = index(k);
|
||||||
auto minimal_perfect_hash = index_.minimal_perfect_hash(k);
|
auto it = begin() + idx;
|
||||||
if (__builtin_expect(present_[minimal_perfect_hash], true)) {
|
if (idx == -1 || it->first != k) return end();
|
||||||
auto vit = values_.begin() + minimal_perfect_hash;
|
return it;
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
if (index_.size() == 0) return -1;
|
if (__builtin_expect(!slack_.empty(), 0)) {
|
||||||
return index_.minimal_perfect_hash(k);
|
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) {
|
MPH_MAP_METHOD_DECL(data_type&, operator[])(const key_type& k) {
|
||||||
|
Loading…
Reference in New Issue
Block a user