-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph.hpp
More file actions
64 lines (52 loc) · 1.54 KB
/
Graph.hpp
File metadata and controls
64 lines (52 loc) · 1.54 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
#ifndef GRAPH_HPP
#define GRAPH_HPP
#include <vector>
const int N = 10;
class Graph
{
private:
std::vector<int> csr_row_offset;
std::vector<int> csr_col_indices;
std::vector<int> csc_col_offset;
std::vector<int> csc_row_indoces;
std::vector<int> values;
int nzz = 0;
int v_num;
public:
Graph(int adjacencyMatrix[][10], int n){
v_num = n;
csr_row_offset.resize(n + 1, 0);
csc_col_offset.resize(n + 1, 0);
csr_row_offset[0] = 0;
csc_col_offset[0] = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (adjacencyMatrix[i][j] != 0) {
csr_col_indices.push_back(j);
values.push_back(1);
}else{
nzz++;
}
}
csr_row_offset[i + 1] = csr_col_indices.size();
}
for (int j = 0; j < n; ++j) {
for (int i = 0; i < n; ++i) {
if (adjacencyMatrix[i][j] != 0) { // If there's an edge from i to j
csc_row_indoces.push_back(i);
}
}
csc_col_offset[j + 1] = csc_row_indoces.size();
}
}
// Getters
std::vector<int>& get_csr_row_offset() { return csr_row_offset; }
std::vector<int>& get_csr_col_indices() { return csr_col_indices; }
std::vector<int>& get_csc_col_offset() { return csc_col_offset; }
std::vector<int>& get_csc_row_indoces() { return csc_row_indoces; }
std::vector<int>& get_values() { return values;}
int get_nzz() const { return nzz; }
int get_v_num() const { return v_num; }
~Graph(){}
};
#endif