All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
hash.hpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2013 Piotr Wygocki
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
15 #ifndef PAAL_HASH_HPP
16 #define PAAL_HASH_HPP
17 
18 #include <boost/functional/hash.hpp>
19 #include <boost/graph/graph_traits.hpp>
20 
21 #include <algorithm>
22 #include <cstddef>
23 
24 namespace paal {
25 
32 template <typename Graph, class Enable = void> struct edge_hash {
33  typedef typename boost::graph_traits<Graph>::edge_descriptor Edge;
41  std::size_t operator()(const Edge &e) const {
42  std::size_t hash = 0;
43  boost::hash_combine(hash, std::min(e.m_source, e.m_target));
44  boost::hash_combine(hash, std::max(e.m_source, e.m_target));
45  return hash;
46  }
47 };
55 template <typename Graph>
56 struct edge_hash<Graph,
57  typename std::enable_if<std::is_same<
58  typename boost::graph_traits<Graph>::directed_category,
59  boost::directed_tag>::value>::type> {
60  typedef typename boost::graph_traits<Graph>::edge_descriptor Edge;
68  std::size_t operator()(const Edge &e) const {
69  std::size_t hash = 0;
70  boost::hash_combine(hash, e.m_source);
71  boost::hash_combine(hash, e.m_target);
72  return hash;
73  }
74 };
75 
84 struct range_hash {
85 
93  template <typename Range>
94  std::size_t operator()(Range && range) const {
95  return boost::hash_range(std::begin(range), std::end(range));
96  }
97 };
98 
99 }
100 
101 #endif // PAAL_HASH_HPP
Functor that can be used as a std::unordered_map/set hash param, when key is a range. copied from: http://stackoverflow.com/questions/10405030/c-unordered-map-fail-when-used-with-a-vector-as-key.
Definition: hash.hpp:84
std::size_t operator()(Range &&range) const
Definition: hash.hpp:94
hash for edge_descriptor in bgl, undirected version
Definition: hash.hpp:32
std::size_t operator()(const Edge &e) const
operator()
Definition: hash.hpp:41