Skip to content

Commit 55e8e57

Browse files
committed
type fix graph implementation
1 parent 0899958 commit 55e8e57

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

include/osp/graph_implementations/adj_list_impl/computational_dag_edge_idx_vector_impl.hpp

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,30 @@ limitations under the License.
2727

2828
namespace osp {
2929

30+
template<typename v_impl>
3031
struct directed_edge_descriptor_impl {
3132

32-
std::size_t idx;
33+
using vertex_idx = typename v_impl::vertex_idx_type;
3334

34-
std::size_t source;
35-
std::size_t target;
35+
vertex_idx idx;
36+
37+
vertex_idx source;
38+
vertex_idx target;
3639

3740
directed_edge_descriptor_impl() : idx(0), source(0), target(0) {}
38-
directed_edge_descriptor_impl(const directed_edge_descriptor_impl &other) = default;
39-
directed_edge_descriptor_impl(directed_edge_descriptor_impl &&other) = default;
40-
directed_edge_descriptor_impl &operator=(const directed_edge_descriptor_impl &other) = default;
41-
directed_edge_descriptor_impl &operator=(directed_edge_descriptor_impl &&other) = default;
42-
directed_edge_descriptor_impl(std::size_t source_arg, std::size_t target_arg, std::size_t idx_arg)
41+
directed_edge_descriptor_impl(const directed_edge_descriptor_impl<v_impl> &other) = default;
42+
directed_edge_descriptor_impl(directed_edge_descriptor_impl<v_impl> &&other) = default;
43+
directed_edge_descriptor_impl &operator=(const directed_edge_descriptor_impl<v_impl> &other) = default;
44+
directed_edge_descriptor_impl &operator=(directed_edge_descriptor_impl<v_impl> &&other) = default;
45+
directed_edge_descriptor_impl(vertex_idx source_arg, vertex_idx target_arg, vertex_idx idx_arg)
4346
: idx(idx_arg), source(source_arg), target(target_arg) {}
4447
~directed_edge_descriptor_impl() = default;
4548

46-
bool operator==(const directed_edge_descriptor_impl &other) const {
49+
bool operator==(const directed_edge_descriptor_impl<v_impl> &other) const {
4750
return idx == other.idx && source == other.source && target == other.target;
4851
}
4952

50-
bool operator!=(const directed_edge_descriptor_impl &other) const { return !(*this == other); }
53+
bool operator!=(const directed_edge_descriptor_impl<v_impl> &other) const { return !(*this == other); }
5154
};
5255

5356
template<typename edge_comm_weight_t>
@@ -66,11 +69,11 @@ template<typename v_impl, typename e_impl>
6669
class computational_dag_edge_idx_vector_impl {
6770
public:
6871
// graph_traits specialization
69-
using vertex_idx = std::size_t;
70-
using directed_edge_descriptor = directed_edge_descriptor_impl;
72+
using vertex_idx = typename v_impl::vertex_idx_type;
73+
using directed_edge_descriptor = directed_edge_descriptor_impl<v_impl>;
7174

72-
using out_edges_iterator_t = std::vector<directed_edge_descriptor>::const_iterator;
73-
using in_edges_iterator_t = std::vector<directed_edge_descriptor>::const_iterator;
75+
using out_edges_iterator_t = typename std::vector<directed_edge_descriptor>::const_iterator;
76+
using in_edges_iterator_t = typename std::vector<directed_edge_descriptor>::const_iterator;
7477

7578
// cdag_traits specialization
7679
using vertex_work_weight_type = typename v_impl::work_weight_type;
@@ -287,10 +290,12 @@ static_assert(
287290

288291
} // namespace osp
289292

290-
template<>
291-
struct std::hash<osp::directed_edge_descriptor_impl> {
292-
std::size_t operator()(const osp::directed_edge_descriptor_impl &p) const noexcept {
293-
auto h1 = std::hash<std::size_t>{}(p.source);
293+
template<typename v_impl>
294+
struct std::hash<osp::directed_edge_descriptor_impl<v_impl>> {
295+
using vertex_idx = typename v_impl::vertex_idx_type;
296+
297+
std::size_t operator()(const osp::directed_edge_descriptor_impl<v_impl> &p) const noexcept {
298+
auto h1 = std::hash<vertex_idx>{}(p.source);
294299
osp::hash_combine(h1, p.target);
295300

296301
return h1;

tests/graph_vector_adapter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ limitations under the License.
2424

2525
#include "osp/graph_algorithms/directed_graph_util.hpp"
2626
#include "osp/graph_implementations/adj_list_impl/computational_dag_vector_impl.hpp"
27+
#include "osp/graph_implementations/adj_list_impl/computational_dag_edge_idx_vector_impl.hpp"
2728
#include "osp/graph_implementations/adj_list_impl/dag_vector_adapter.hpp"
2829
#include "osp/graph_implementations/boost_graphs/boost_graph.hpp"
2930
#include "osp/graph_implementations/adj_list_impl/compact_sparse_graph.hpp"
@@ -50,7 +51,8 @@ BOOST_AUTO_TEST_CASE(test_dag_vector_adapter) {
5051

5152
using v_impl = cdag_vertex_impl<unsigned, int, int, int, unsigned>;
5253
using graph_t = dag_vector_adapter<v_impl,int>;
53-
using graph_constr_t = computational_dag_vector_impl<v_impl>;
54+
//using graph_constr_t = computational_dag_vector_impl<v_impl>;
55+
using graph_constr_t = computational_dag_edge_idx_vector_impl<v_impl, cdag_edge_impl_int>;
5456
using CoarseGraphType = Compact_Sparse_Graph<true, true, true, true, true, vertex_idx_t<graph_t>, std::size_t, v_workw_t<graph_t>, v_workw_t<graph_t>, v_workw_t<graph_t>, v_type_t<graph_t>>;
5557

5658
graph_t graph(out_neighbors, in_neighbors);

0 commit comments

Comments
 (0)