Compiles with clang in mac.
This commit is contained in:
parent
bb40a4bb00
commit
bbfcdeb5a6
@ -18,9 +18,9 @@ class Benchmark {
|
|||||||
static void RunAll();
|
static void RunAll();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool SetUp() {};
|
virtual bool SetUp() { return true; };
|
||||||
virtual void Run() = 0;
|
virtual void Run() = 0;
|
||||||
virtual bool TearDown() {};
|
virtual bool TearDown() { return true; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string name_;
|
std::string name_;
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <tr1/unordered_map>
|
||||||
|
|
||||||
#include "bm_common.h"
|
#include "bm_common.h"
|
||||||
#include "mph_map.h"
|
#include "mph_map.h"
|
||||||
|
|
||||||
using cxxmph::mph_map;
|
using cxxmph::mph_map;
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::unordered_map;
|
using std::tr1::unordered_map;
|
||||||
|
|
||||||
namespace cxxmph {
|
namespace cxxmph {
|
||||||
|
|
||||||
template <class MapType>
|
template <class MapType>
|
||||||
class BM_MapCreate : public UrlsBenchmark {
|
class BM_MapCreate : public UrlsBenchmark {
|
||||||
public:
|
public:
|
||||||
|
BM_MapCreate(const string& urls_file) : UrlsBenchmark(urls_file) { }
|
||||||
virtual void Run() {
|
virtual void Run() {
|
||||||
MapType mymap;
|
MapType mymap;
|
||||||
for (auto it = urls_.begin(); it != urls_.end(); ++it) {
|
for (auto it = urls_.begin(); it != urls_.end(); ++it) {
|
||||||
@ -24,17 +25,20 @@ class BM_MapCreate : public UrlsBenchmark {
|
|||||||
template <class MapType>
|
template <class MapType>
|
||||||
class BM_MapSearch : public SearchUrlsBenchmark {
|
class BM_MapSearch : public SearchUrlsBenchmark {
|
||||||
public:
|
public:
|
||||||
|
BM_MapSearch(const std::string& urls_file, int nsearches)
|
||||||
|
: SearchUrlsBenchmark(urls_file, nsearches) { }
|
||||||
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 value = mymap[*it];
|
auto value = mymap_[it->ToString()];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
virtual void SetUp() {
|
virtual bool SetUp() {
|
||||||
for (auto it = urls_.begin(); it != urls_.end(); ++it) {
|
for (auto it = urls_.begin(); it != urls_.end(); ++it) {
|
||||||
mymap_[*it] = *it;
|
mymap_[*it] = *it;
|
||||||
}
|
}
|
||||||
mymap_.resize(mymap.size());
|
mymap_.rehash(mymap_.bucket_count());
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
MapType mymap_;
|
MapType mymap_;
|
||||||
};
|
};
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <unordered_map> // for std::hash
|
#include <tr1/unordered_map> // for std::tr1::hash
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -158,7 +158,7 @@ uint32_t MPHIndex::index(const Key& key) const {
|
|||||||
return Rank(vertex);
|
return Rank(vertex);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Key, class HashFcn = typename seeded_hash<std::hash<Key> >::hash_function>
|
template <class Key, class HashFcn = typename seeded_hash<std::tr1::hash<Key> >::hash_function>
|
||||||
class SimpleMPHIndex : public MPHIndex {
|
class SimpleMPHIndex : public MPHIndex {
|
||||||
public:
|
public:
|
||||||
template <class ForwardIterator>
|
template <class ForwardIterator>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <unordered_map>
|
#include <tr1/unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <utility> // for std::pair
|
#include <utility> // for std::pair
|
||||||
|
|
||||||
@ -8,12 +8,14 @@
|
|||||||
|
|
||||||
namespace cxxmph {
|
namespace cxxmph {
|
||||||
|
|
||||||
|
using std::tr1::unordered_map;
|
||||||
|
|
||||||
// Save on repetitive typing.
|
// Save on repetitive typing.
|
||||||
#define MPH_MAP_TMPL_SPEC template <class Key, class Data, class HashFcn, class EqualKey, class Alloc>
|
#define MPH_MAP_TMPL_SPEC template <class Key, class Data, class HashFcn, class EqualKey, class Alloc>
|
||||||
#define MPH_MAP_CLASS_SPEC mph_map<Key, Data, HashFcn, EqualKey, Alloc>
|
#define MPH_MAP_CLASS_SPEC mph_map<Key, Data, HashFcn, EqualKey, Alloc>
|
||||||
#define MPH_MAP_METHOD_DECL(r, m) MPH_MAP_TMPL_SPEC typename MPH_MAP_CLASS_SPEC::r MPH_MAP_CLASS_SPEC::m
|
#define MPH_MAP_METHOD_DECL(r, m) MPH_MAP_TMPL_SPEC typename MPH_MAP_CLASS_SPEC::r MPH_MAP_CLASS_SPEC::m
|
||||||
|
|
||||||
template <class Key, class Data, class HashFcn = std::hash<Key>, class EqualKey = std::equal_to<Key>, class Alloc = std::allocator<Data> >
|
template <class Key, class Data, class HashFcn = std::tr1::hash<Key>, class EqualKey = std::equal_to<Key>, class Alloc = std::allocator<Data> >
|
||||||
class mph_map {
|
class mph_map {
|
||||||
public:
|
public:
|
||||||
typedef Key key_type;
|
typedef Key key_type;
|
||||||
@ -52,7 +54,8 @@ class mph_map {
|
|||||||
const_iterator find(const key_type& k) const;
|
const_iterator find(const key_type& k) const;
|
||||||
data_type& operator[](const key_type &k);
|
data_type& operator[](const key_type &k);
|
||||||
|
|
||||||
void pack() { rehash(); }
|
size_type bucket_count() const { return size(); }
|
||||||
|
void rehash(size_type nbuckets /*ignored*/) { pack(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template <typename iterator>
|
template <typename iterator>
|
||||||
@ -68,11 +71,11 @@ class mph_map {
|
|||||||
return iterator_first<iterator>(it);
|
return iterator_first<iterator>(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rehash();
|
void pack();
|
||||||
std::vector<value_type> values_;
|
std::vector<value_type> values_;
|
||||||
SimpleMPHIndex<Key, typename seeded_hash<HashFcn>::hash_function> index_;
|
SimpleMPHIndex<Key, typename seeded_hash<HashFcn>::hash_function> index_;
|
||||||
// TODO(davi) optimize slack to no hold a copy of the key
|
// TODO(davi) optimize slack to no hold a copy of the key
|
||||||
typedef typename std::unordered_map<Key, uint32_t, HashFcn, EqualKey, Alloc> slack_type;
|
typedef unordered_map<Key, uint32_t, HashFcn, EqualKey, Alloc> slack_type;
|
||||||
slack_type slack_;
|
slack_type slack_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -82,7 +85,7 @@ bool operator==(const MPH_MAP_CLASS_SPEC& lhs, const MPH_MAP_CLASS_SPEC& rhs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MPH_MAP_TMPL_SPEC MPH_MAP_CLASS_SPEC::mph_map() {
|
MPH_MAP_TMPL_SPEC MPH_MAP_CLASS_SPEC::mph_map() {
|
||||||
rehash();
|
pack();
|
||||||
}
|
}
|
||||||
|
|
||||||
MPH_MAP_TMPL_SPEC MPH_MAP_CLASS_SPEC::~mph_map() {
|
MPH_MAP_TMPL_SPEC MPH_MAP_CLASS_SPEC::~mph_map() {
|
||||||
@ -95,13 +98,13 @@ MPH_MAP_METHOD_DECL(insert_return_type, insert)(const value_type& x) {
|
|||||||
slack_.insert(std::make_pair(x.first, values_.size() - 1));
|
slack_.insert(std::make_pair(x.first, values_.size() - 1));
|
||||||
if (slack_.size() == index_.size() ||
|
if (slack_.size() == index_.size() ||
|
||||||
(slack_.size() >= 256 && index_.size() == 0)) {
|
(slack_.size() >= 256 && index_.size() == 0)) {
|
||||||
rehash();
|
pack();
|
||||||
}
|
}
|
||||||
it = find(x.first);
|
it = find(x.first);
|
||||||
return std::make_pair(it, true);
|
return std::make_pair(it, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
MPH_MAP_METHOD_DECL(void_type, rehash)() {
|
MPH_MAP_METHOD_DECL(void_type, pack)() {
|
||||||
if (values_.empty()) return;
|
if (values_.empty()) return;
|
||||||
slack_type().swap(slack_);
|
slack_type().swap(slack_);
|
||||||
bool success = index_.Reset(
|
bool success = index_.Reset(
|
||||||
@ -123,6 +126,7 @@ 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, begin)() const { return values_.begin(); }
|
||||||
MPH_MAP_METHOD_DECL(const_iterator, end)() const { return values_.end(); }
|
MPH_MAP_METHOD_DECL(const_iterator, end)() const { return values_.end(); }
|
||||||
MPH_MAP_METHOD_DECL(bool_type, empty)() const { return values_.empty(); }
|
MPH_MAP_METHOD_DECL(bool_type, empty)() const { return values_.empty(); }
|
||||||
|
MPH_MAP_METHOD_DECL(size_type, size)() const { return values_.size(); }
|
||||||
|
|
||||||
MPH_MAP_METHOD_DECL(void_type, clear)() {
|
MPH_MAP_METHOD_DECL(void_type, clear)() {
|
||||||
values_.clear();
|
values_.clear();
|
||||||
@ -132,7 +136,7 @@ MPH_MAP_METHOD_DECL(void_type, clear)() {
|
|||||||
|
|
||||||
MPH_MAP_METHOD_DECL(void_type, erase)(iterator pos) {
|
MPH_MAP_METHOD_DECL(void_type, erase)(iterator pos) {
|
||||||
values_.erase(pos);
|
values_.erase(pos);
|
||||||
rehash();
|
pack();
|
||||||
}
|
}
|
||||||
MPH_MAP_METHOD_DECL(void_type, erase)(const key_type& k) {
|
MPH_MAP_METHOD_DECL(void_type, erase)(const key_type& k) {
|
||||||
iterator it = find(k);
|
iterator it = find(k);
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include <stdint.h> // for uint32_t and friends
|
#include <stdint.h> // for uint32_t and friends
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <unordered_map> // for std::hash
|
#include <tr1/unordered_map> // for std::tr1::hash
|
||||||
|
|
||||||
#include "MurmurHash2.h"
|
#include "MurmurHash2.h"
|
||||||
#include "stringpiece.h"
|
#include "stringpiece.h"
|
||||||
@ -52,34 +52,34 @@ struct seeded_hash_function<Murmur2StringPiece> {
|
|||||||
|
|
||||||
template <class HashFcn> struct seeded_hash
|
template <class HashFcn> struct seeded_hash
|
||||||
{ typedef seeded_hash_function<HashFcn> hash_function; };
|
{ typedef seeded_hash_function<HashFcn> hash_function; };
|
||||||
// Use Murmur2 instead for all types defined in std::hash, plus
|
// Use Murmur2 instead for all types defined in std::tr1::hash, plus
|
||||||
// std::string which is commonly extended.
|
// std::string which is commonly extended.
|
||||||
template <> struct seeded_hash<std::hash<char*> >
|
template <> struct seeded_hash<std::tr1::hash<char*> >
|
||||||
{ typedef seeded_hash_function<Murmur2StringPiece> hash_function; };
|
{ typedef seeded_hash_function<Murmur2StringPiece> hash_function; };
|
||||||
template <> struct seeded_hash<std::hash<const char*> >
|
template <> struct seeded_hash<std::tr1::hash<const char*> >
|
||||||
{ typedef seeded_hash_function<Murmur2StringPiece> hash_function; };
|
{ typedef seeded_hash_function<Murmur2StringPiece> hash_function; };
|
||||||
template <> struct seeded_hash<std::hash<std::string> >
|
template <> struct seeded_hash<std::tr1::hash<std::string> >
|
||||||
{ typedef seeded_hash_function<Murmur2StringPiece> hash_function; };
|
{ typedef seeded_hash_function<Murmur2StringPiece> hash_function; };
|
||||||
|
|
||||||
template <> struct seeded_hash<std::hash<char> >
|
template <> struct seeded_hash<std::tr1::hash<char> >
|
||||||
{ typedef seeded_hash_function<Murmur2> hash_function; };
|
{ typedef seeded_hash_function<Murmur2> hash_function; };
|
||||||
template <> struct seeded_hash<std::hash<unsigned char> >
|
template <> struct seeded_hash<std::tr1::hash<unsigned char> >
|
||||||
{ typedef seeded_hash_function<Murmur2> hash_function; };
|
{ typedef seeded_hash_function<Murmur2> hash_function; };
|
||||||
template <> struct seeded_hash<std::hash<short> >
|
template <> struct seeded_hash<std::tr1::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::tr1::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::tr1::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::tr1::hash<unsigned int> >
|
||||||
{ typedef seeded_hash_function<Murmur2> hash_function; };
|
{ typedef seeded_hash_function<Murmur2> hash_function; };
|
||||||
template <> struct seeded_hash<std::hash<long> >
|
template <> struct seeded_hash<std::tr1::hash<long> >
|
||||||
{ typedef seeded_hash_function<Murmur2> hash_function; };
|
{ typedef seeded_hash_function<Murmur2> hash_function; };
|
||||||
template <> struct seeded_hash<std::hash<unsigned long> >
|
template <> struct seeded_hash<std::tr1::hash<unsigned long> >
|
||||||
{ typedef seeded_hash_function<Murmur2> hash_function; };
|
{ typedef seeded_hash_function<Murmur2> hash_function; };
|
||||||
template <> struct seeded_hash<std::hash<long long> >
|
template <> struct seeded_hash<std::tr1::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::tr1::hash<unsigned long long> >
|
||||||
{ typedef seeded_hash_function<Murmur2> hash_function; };
|
{ typedef seeded_hash_function<Murmur2> hash_function; };
|
||||||
|
|
||||||
} // namespace cxxmph
|
} // namespace cxxmph
|
||||||
|
Loading…
Reference in New Issue
Block a user