All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
metric_on_idx.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_METRIC_ON_IDX_HPP
16 #define PAAL_METRIC_ON_IDX_HPP
17 
20 
21 namespace paal {
22 namespace data_structures {
23 
24 
25 struct read_values_tag{};
27 
35 template <typename Metric, typename Bimap, typename Strategy = read_indexes_tag> class metric_on_idx {
36  Metric m_metric;
37  Bimap m_idx;
39 
40  auto read(typename btraits::Val v, read_values_tag) const -> decltype(m_idx.get_idx(v)) {
41  return m_idx.get_idx(v);
42  }
43 
44  auto read(typename btraits::Idx v, read_indexes_tag) const -> decltype(m_idx.get_val(v)) {
45  return m_idx.get_val(v);
46  }
47 
48  template <typename Vertex>
49  auto read(Vertex && v) const -> decltype(this->read(v, Strategy())) {
50  return read(v, Strategy{});
51  }
52 
53  public:
54 
61  metric_on_idx(Metric m, Bimap idx)
62  : m_metric(m), m_idx(idx) {}
63 
72  template <typename Vertex>
73  auto operator()(const Vertex & i, const Vertex & j) {
74  return m_metric(read(i), read(j));
75  }
76 
85  template <typename Vertex>
86  auto operator()(const Vertex & i, const Vertex & j) const {
87  return m_metric(read(i), read(j));
88  }
89 };
90 
101 template <typename Strategy = read_indexes_tag, typename Metric, typename Bimap>
103  Bimap && b) {
104  return metric_on_idx<Metric, Bimap, Strategy>(std::forward<Metric>(m), std::forward<Bimap>(b));
105 }
106 
107 
108 template <typename Metric, typename Bimap>
110 public _metric_traits<metric_on_idx<Metric, Bimap, read_indexes_tag>,
111  typename bimap_traits<typename std::decay<Bimap>::type>::Idx>
112 {};
113 
114 template <typename Metric, typename Bimap>
115 struct metric_traits<metric_on_idx<Metric, Bimap, read_values_tag>> :
116 public _metric_traits<metric_on_idx<Metric, Bimap, read_values_tag>,
117  typename bimap_traits<typename std::decay<Bimap>::type>::Val>
118 {};
119 
120 
121 }
122 }
123 #endif // PAAL_METRIC_ON_IDX_HPP
metric_on_idx< Metric, Bimap, Strategy > make_metric_on_idx(Metric &&m, Bimap &&b)
make for metric_on_idx
auto operator()(const Vertex &i, const Vertex &j) const
operator() const
This metric keeps inner metric and index. Given vertices are reindex and passed to inner metric...
metric_on_idx(Metric m, Bimap idx)
constructor
auto operator()(const Vertex &i, const Vertex &j)
operator()