-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMygraph.cpp
More file actions
52 lines (45 loc) · 1.25 KB
/
Copy pathMygraph.cpp
File metadata and controls
52 lines (45 loc) · 1.25 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
#include "Mygraph.h"
MyGraph::MyGraph()
{
}
MyGraph::~MyGraph()
{
}
void MyGraph::AddEdge(int from, int to)
{
this->edges.push_back(Edge(from, to));
this->out_degree[from]++;
this->in_degree[to]++;
int m = edges.size();
G[from].push_back(m - 1); //湖荂棒唗甡懇
G_2[to].push_back(m - 1); //湖荂棒唗甡懇
G_3[to].push_back(m - 1); //湖荂棒唗+崝第癲袉甡懇
}
void MyGraph::AddEdge_2(int from, int to)
{
this->edges.push_back(Edge(from, to));
this->out_degree[from]++;
this->in_degree[to]++;
int m = edges.size();
G_3[to].push_back(m - 1);
//G_2[to].push_back(m - 1);
}
void MyGraph::UpdateDegree(int node_id, int change)
{
std::cout << "update degree: node_id: " << node_id << " change: " << change << std::endl;
for (int i = 0; i < G[node_id].size(); i++) {
if (edge_deleted[G[node_id][i]]) continue;
int to = this->edges[G[node_id][i]].GetTo();
this->in_degree[to] += change;
}
this->out_degree[node_id] += change * G[node_id].size();
}
void MyGraph::UpdateDegree_2(int node_id, int change)
{
for (int i = 0; i < G_3[node_id].size(); i++) {
if (edge_deleted[G_3[node_id][i]]) continue;
int from = this->edges[G_3[node_id][i]].GetFrom();
this->out_degree[from] += change;
}
this->in_degree[node_id] += change * G_3[node_id].size();
}