Commit 5d4b96c0 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Fix additional issues with std::hash<> specializations

parent 4d8ac23d
......@@ -30,6 +30,7 @@
#include "graph.hh"
#include "graph_selectors.hh"
#include "graph_properties.hh"
#include "graph_util.hh"
#include "random.hh"
......
......@@ -41,49 +41,6 @@
#include <omp.h>
#endif
namespace std
{
template <size_t pos, class... T>
struct tuple_combine
{
void operator()(size_t& seed, const std::tuple<T...>& v) const
{
boost::hash_combine(seed, std::get<pos-1>(v));
tuple_combine<pos-1, T...>()(seed, v);
}
};
template <class... T>
struct tuple_combine<0, T...>
{
void operator()(size_t& seed, const std::tuple<T...>& v) const {}
};
template <class... T>
struct hash<std::tuple<T...>>
{
size_t operator()(std::tuple<T...> const& v) const
{
std::size_t seed = 0;
tuple_combine<sizeof...(T), T...>()(seed, v);
return seed;
}
};
template <class T1, class T2>
struct hash<std::pair<T1, T2>>
{
size_t operator()(std::pair<T1, T2> const& v) const
{
std::size_t seed = 0;
boost::hash_combine(seed, v.first);
boost::hash_combine(seed, v.second);
return seed;
}
};
}
double spence(double);
......
......@@ -31,6 +31,7 @@
#include "graph.hh"
#include "graph_selectors.hh"
#include "graph_properties.hh"
#include "graph_util.hh"
#include "random.hh"
......
......@@ -232,7 +232,7 @@ public:
typedef std::tuple<size_t, size_t, size_t> key_t; // u, r, s
#ifdef HAVE_SPARSEHASH
dense_hash_map<key_t, int> out_us;
dense_hash_map<key_t, int, std::hash<key_t>> out_us;
out_us.set_empty_key(key_t(numeric_limits<size_t>::max(),
numeric_limits<size_t>::max(),
numeric_limits<size_t>::max()));
......@@ -344,15 +344,15 @@ struct overlap_partition_stats_t
typedef vector<int> bv_t;
#ifdef HAVE_SPARSEHASH
typedef dense_hash_map<bv_t, size_t> bhist_t;
typedef dense_hash_map<cdeg_t, size_t> cdeg_hist_t;
typedef dense_hash_map<bv_t, size_t, std::hash<bv_t>> bhist_t;
typedef dense_hash_map<cdeg_t, size_t, std::hash<cdeg_t>> cdeg_hist_t;
typedef dense_hash_map<bv_t, cdeg_hist_t> deg_hist_t;
typedef dense_hash_map<bv_t, cdeg_hist_t, std::hash<bv_t>> deg_hist_t;
typedef dense_hash_map<bv_t, vector<size_t>> ebhist_t;
typedef dense_hash_map<bv_t, vector<size_t>, std::hash<bv_t>> ebhist_t;
#else
typedef unordered_map<bv_t, size_t> bhist_t;
typedef unordered_map<cdeg_t, size_t> cdeg_hist_t;
typedef unordered_map<cdeg_t, size_t, std::hash<cdeg_t>> cdeg_hist_t;
typedef unordered_map<bv_t, cdeg_hist_t> deg_hist_t;
......
......@@ -509,18 +509,66 @@ private:
//
// Vector hash function
// Useful hash<> specializations
//
namespace std
{
template <class Val>
void _hash_combine(size_t& seed, const Val& hash)
{
seed ^= std::hash<Val>()(hash) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
template <size_t pos, class... T>
struct tuple_combine
{
void operator()(size_t& seed, const std::tuple<T...>& v) const
{
std::_hash_combine(seed, std::get<pos-1>(v));
tuple_combine<pos-1, T...>()(seed, v);
}
};
template <class... T>
struct tuple_combine<0, T...>
{
void operator()(size_t& seed, const std::tuple<T...>& v) const {}
};
template <class... T>
struct hash<std::tuple<T...>>
{
size_t operator()(std::tuple<T...> const& v) const
{
std::size_t seed = 0;
tuple_combine<sizeof...(T), T...>()(seed, v);
return seed;
}
};
template <class T1, class T2>
struct hash<std::pair<T1, T2>>
{
size_t operator()(std::pair<T1, T2> const& v) const
{
std::size_t seed = 0;
std::_hash_combine(seed, v.first);
std::_hash_combine(seed, v.second);
return seed;
}
};
template <class Value>
struct hash<vector<Value>>
{
size_t operator()(const vector<Value>& v) const
{
return boost::hash_range(v.begin(), v.end());
size_t seed = 0;
for (const auto& x : v)
std::_hash_combine(seed, x);
return seed;
}
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment