forked from yoann-dufresne/ComponentSearch2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Graph.hpp
70 lines (49 loc) · 946 Bytes
/
Graph.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <vector>
#include <iostream>
using namespace std;
#ifndef NODE_HPP
#define NODE_HPP
class Node {
public:
int idx;
vector<int> neighbors;
Node ();
Node (int idx);
void print ();
bool operator==(const Node &other) const;
};
class MetaNode : public Node {
public:
vector<Node> subNodes;
MetaNode ();
void print();
};
template <typename N>
class Graph {
public:
vector<N> nodes;
Graph();
N & getNodeFromIdx (int idx);
long getEdgesNb();
void print();
};
/* ----- Template implementations ----- */
template <typename N>
Graph<N>::Graph() {}
template <typename N>
void Graph<N>::print() {
for (N node : nodes)
node.print();
}
template <typename N>
N & Graph<N>::getNodeFromIdx (int idx) {
return *(find(nodes.begin(), nodes.end(), Node(idx)));
}
template <typename N>
long Graph<N>::getEdgesNb() {
long edgesNb = 0;
for (N node: nodes)
edgesNb += node.neighbors.size();
return edgesNb / 2;
}
#endif