-
Notifications
You must be signed in to change notification settings - Fork 4
/
Graph.h
67 lines (49 loc) · 1.26 KB
/
Graph.h
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
/**
* Header file to read and store Graphs
*
* @author Ashwin Joisa
* @author Praveen Gupta
**/
//=============================================================================================//
#include <bits/stdc++.h>
using namespace std;
class Graph {
public:
int nodeCount, edgeCount;
int *adjacencyList, *adjacencyListPointers;
int *edgeList1, *edgeList2;
public:
int getNodeCount() {
return nodeCount;
}
int getEdgeCount() {
return edgeCount;
}
// Reads the graph and stores in Compressed Sparse Row (CSR) format
void readGraph() {
// Reading in CSR format
cin >> nodeCount >> edgeCount;
// Copy into compressed adjacency List
adjacencyListPointers = new int[nodeCount +1];
adjacencyList = new int[2 * edgeCount +1];
for(int i=0; i<=nodeCount; i++)
cin >> adjacencyListPointers[i];
for(int i=0; i<(2 * edgeCount); i++)
cin >> adjacencyList[i];
}
void convertToCOO() {
edgeList2 = adjacencyList;
edgeList1 = new int[2 * edgeCount +1];
for(int i=0; i <nodeCount; ++i) {
for(int j=adjacencyListPointers[i]; j<adjacencyListPointers[i+1]; ++j){
edgeList1[j] = i;
}
}
}
int *getAdjacencyList(int node) {
return adjacencyList;
}
int *getAdjacencyListPointers(int node) {
return adjacencyListPointers;
}
};