-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcsr_uint.cpp
More file actions
135 lines (107 loc) · 3.12 KB
/
csr_uint.cpp
File metadata and controls
135 lines (107 loc) · 3.12 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include<iostream>
#include<fstream>
#include<map>
#include<vector>
#include<cstdlib>
#include<algorithm>
#include<set>
#define CH printf("check!!\n");
using namespace std;
int main(int argc,char *argv[])
{
ifstream infile1(argv[1]);
ofstream outfile(argv[2],ios_base::out | ios_base::binary);
string str1,str2;
unsigned int node1,node2;
map<unsigned int , unsigned int> mp2;
unsigned int node_count;
node_count = 0;
unsigned int index_size = 0;
cout << "create_node_number_map" << endl;
while(getline(infile1,str1,'\t')){
getline(infile1,str2);
node1 = atoi(str1.c_str());
node2 = atoi(str2.c_str());
if(node1 != node2){
if(mp2.find(node1) == mp2.end()){
mp2[node1] = node_count;
node_count++;
}
index_size++;
if(mp2.find(node2) == mp2.end()){
mp2[node2] = node_count;
node_count++;
}
}
}
ifstream infile2(argv[1]);
unsigned int *edge_list = new unsigned int[index_size*2];
unsigned int edge_count = 0;
cout << "create_edge_list" << endl;
while(getline(infile2,str1,'\t')){
getline(infile2,str2);
node1 = atoi(str1.c_str());
node2 = atoi(str2.c_str());
if(node1 != node2){
edge_list[edge_count] = mp2[node1];
edge_count++;
edge_list[edge_count] = mp2[node2];
edge_count++;
}
}
mp2.clear();
unsigned int c = 0;
unsigned int *node = new unsigned int[node_count + 1];
node[0] = 0;
ofstream log("logfile.txt",ios_base::out | ios_base::binary);
cout << "create_node_array" << endl;
while(c < node_count){
map<unsigned int,set<unsigned int>> mp;
unsigned int c0 = c;
unsigned int c2 = c+100000;
if(c2 >= node_count){
c2 = node_count;
}
for(unsigned int i = 0;i < index_size*2;i+=2){
if(c <= edge_list[i] && edge_list[i] < c2){
mp[edge_list[i]].insert(edge_list[i+1]);
}
if(c <= edge_list[i+1] && edge_list[i+1] < c2){
mp[edge_list[i+1]].insert(edge_list[i]);
}
}
while(c<c2){
unsigned int index = mp[c].size();
node[c+1] = node[c] + index;
c++;
}
unsigned int edgesize = node[c] - node[c0];
cout << edgesize << endl;
unsigned int *edge_log = new unsigned int[edgesize];
unsigned int n = 0;
// cout << "aaa" << endl;
while(c0 < c2){
for(auto itr = mp[c0].begin();itr != mp[c0].end();++itr){
edge_log[n] = *itr;
n++;
}
c0++;
}
log.write((const char*)&edge_log[0],sizeof(unsigned int)*edgesize);
delete[] edge_log;
mp.clear();
}
cout << "write_file" << endl;
unsigned int node_total = node_count + 1;
unsigned int edge_total = node[node_count];
outfile.write((const char*)&node_count,sizeof(int));
outfile.write((const char*)&edge_total,sizeof(int));
outfile.write((const char*)&node[0],sizeof(int)*(node_total));
delete[] node;
ifstream infile3("logfile.txt",ios_base::in | ios_base::binary);
unsigned int *edge = new unsigned int[edge_total];
infile3.read((char*)&edge[0],sizeof(int)*(edge_total));
outfile.write((const char*)(edge),sizeof(int)*(edge_total));
log.close();
remove("logfile.txt");
}