MCPcopy Create free account
hub / github.com/DeepGraphLearning/graphvite / GraphMixin

Class GraphMixin

include/core/graph.h:46–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44 */
45template<class _Index, class ..._Attributes>
46class GraphMixin {
47public:
48 typedef _Index Index;
49 typedef std::tuple<Index, float, _Attributes...> VertexEdge;
50 typedef std::tuple<Index, Index, float, _Attributes...> Edge;
51
52 std::vector<std::vector<VertexEdge>> vertex_edges;
53 std::vector<Edge> edges;
54 std::vector<float> vertex_weights, edge_weights;
55 std::vector<size_t> flat_offsets;
56
57 Index num_vertex;
58 size_t num_edge;
59
60#define USING_GRAPH_MIXIN(type) \
61 using typename type::VertexEdge; \
62 using typename type::Edge; \
63 using type::vertex_edges; \
64 using type::edges; \
65 using type::vertex_weights; \
66 using type::edge_weights; \
67 using type::num_vertex; \
68 using type::num_edge; \
69 using type::info
70
71 GraphMixin() = default;
72 GraphMixin(const GraphMixin &) = delete;
73 GraphMixin &operator=(const GraphMixin &) = delete;
74
75 /** Clear the graph and free CPU memory */
76 virtual void clear() {
77 num_vertex = 0;
78 num_edge = 0;
79 decltype(vertex_edges)().swap(vertex_edges);
80 decltype(edges)().swap(edges);
81 decltype(vertex_weights)().swap(vertex_weights);
82 decltype(edge_weights)().swap(edge_weights);
83 decltype(flat_offsets)().swap(flat_offsets);
84 }
85
86 /** Flatten the adjacency list to an edge list */
87 virtual void flatten() {
88 if (!edges.empty())
89 return;
90
91 size_t offset = 0;
92 flat_offsets.resize(num_vertex);
93 for (Index u = 0; u < num_vertex; u++) {
94 for (auto &&vertex_edge : vertex_edges[u]) {
95 edges.push_back(std::tuple_cat(std::tie(u), vertex_edge));
96 edge_weights.push_back(std::get<1>(vertex_edge));
97 }
98 flat_offsets[u] = offset;
99 offset += vertex_edges[u].size();
100 }
101 }
102
103 virtual inline std::string name() const {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected