forked from SNUCSE-CTA/graph-analysis-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph.h
More file actions
109 lines (87 loc) · 3.31 KB
/
graph.h
File metadata and controls
109 lines (87 loc) · 3.31 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#ifndef GRAPH_H
#define GRAPH_H
#include <list>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include "stat.h"
#include "plot.h"
namespace snu {
class Graph; // graph having common aspects
class DSGraph; // directed simple graph
class USGraph; // undirected simple graph
class Graph {
public:
typedef long long Vid; // vertex id
typedef long long Eid; // edge id
typedef std::string Vlabel; // vertex label
typedef std::string Elabel; // edge label
typedef int Weight; // integer type weight, other types of weight can be added
class Vertex;
class Edge;
class LabelOfVertices;
class LabelOfEdges;
class Vertex {
public:
Vid id;
std::list<LabelOfVertices*> labels;
std::list<Edge*> edges;
long long indegree;
void *temp;
};
class Edge {
public:
Eid id;
std::list<LabelOfEdges*> labels;
Vertex *from; // In case of undirected graphs, there is no difference between from and to.
Vertex *to;
Weight weight;
};
class LabelOfVertices {
public:
Vlabel label;
std::list<Vertex*> vertices;
};
class LabelOfEdges {
public:
Elabel label;
std::list<Edge*> edges;
};
std::unordered_map<Vid, Vertex*> id_to_vertex;
std::unordered_map<Eid, Edge*> id_to_edge;
std::unordered_map<Vlabel, LabelOfVertices*> vlabel_to_class;
std::unordered_map<Elabel, LabelOfEdges*> elabel_to_class;
struct pair_hash {
inline unsigned long long operator()(const std::pair<Vid, Vid> &v) const {
return ((unsigned long long)v.first << 32) + v.second;
}
};
std::unordered_set<std::pair<Vid, Vid>, pair_hash> is_connected;
long long negative_edge_num = 0;
char visit = 0;
Graph(); // prevent from creating Graph class and allow creating graph in subclass
~Graph(); // destructor
// add vertex
// if vertex is created normally, then return 0
// if error occurs, then return 1
int addVertex(Vid id, long long num, Vlabel label[]); // array version
int addVertex(Vid id, std::vector <Vlabel> *label); // vector version
// directed form of addEdge
// if edge is created normally, then return 0
// if error occurs, then return 1
int addEdge(Eid id, long long num, Elabel label[], Vid from, Vid to, Weight weight); // array version
};
// directed simple graph
class DSGraph: public Graph {
public:
int addEdge(Eid id, long long num, Elabel label[], Vid from, Vid to, Weight weight); // array version
int addEdge(Eid id, std::vector <Elabel> *label, Vid from, Vid to, Weight weight); // vector version
};
// undirected simple graph
class USGraph: public Graph {
public:
int addEdge(Eid id, long long num, Elabel label[], Vid from, Vid to, Weight weight); // array version
int addEdge(Eid id, std::vector <Elabel> *label, Vid from, Vid to, Weight weight); // vector version
};
}
#endif // GRAPH_H