-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.h
175 lines (166 loc) · 4.44 KB
/
utils.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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include <string.h>
unsigned long long peak_mem()
{
char buf[1024];
FILE* fp;
unsigned long long peaksize;
fp = fopen("/proc/self/status", "r");
if (fp == NULL)
{
cout << "fp = null" << endl;
return -1;
}
while (fgets(buf, sizeof(buf) - 1, fp) != NULL)
{
if (sscanf(buf, "VmSize:%llu", &peaksize) > 0)
{
break;
}
}
fclose(fp);
return peaksize;
}
unsigned long long peak_rss()
{
char buf[1024];
FILE* fp;
unsigned long long peaksize;
fp = fopen("/proc/self/status", "r");
if (fp == NULL)
{
cout << "fp = null" << endl;
return -1;
}
while (fgets(buf, sizeof(buf) - 1, fp) != NULL)
{
if (sscanf(buf, "VmHWM:%llu", &peaksize) > 0)
{
break;
}
}
fclose(fp);
return peaksize;
}
int mkpath(string s, mode_t mode = 0755)
{
size_t pre = 0, pos;
string dir;
int mdret;
if (s[s.size() - 1] != '/')
{
s += '/';
}
while ((pos = s.find_first_of('/', pre)) != string::npos)
{
dir = s.substr(0, pos++);
pre = pos;
if (dir.size() == 0)
continue;
if ((mdret = ::mkdir(dir.c_str(), mode)) && errno != EEXIST)
{
return mdret;
}
}
return mdret;
}
void readGraphAttr(string filelabel, string filedir, uint& n, uint& m)
{
string graphAttr = filedir + filelabel + ".attribute";
cout << "Read graph attributes..." << endl;
cout << "FilePath: " << graphAttr.c_str() << endl;
ifstream graphAttrIn(graphAttr.c_str());
string tmp;
graphAttrIn >> tmp >> n;
graphAttrIn >> tmp >> m;
cout << "n=" << n << endl;
graphAttrIn.close();
return;
}
void readGraph(string filelabel, string filedir, uint* outEL, uint* outPL, double* outWEL, uint n, uint m, int sorted)
{
string neiNode, neiWeight, neiNum;
if (sorted)
{
neiNode = filedir + filelabel + ".outSortedEdges";
neiWeight = filedir + filelabel + ".outSortedWEdges";
neiNum = filedir + filelabel + ".outPtr";
}
else
{
neiNode = filedir + filelabel + ".outEdges";
neiWeight = filedir + filelabel + ".outWEdges";
neiNum = filedir + filelabel + ".outPtr";
}
cout << "Read graph ..." << endl;
ifstream neiNumIn(neiNum.c_str(), ios::in | ios::binary);
ifstream neiWeightIn(neiWeight.c_str(), ios::in | ios::binary);
ifstream neiNodeIn(neiNode.c_str(), ios::in | ios::binary);
neiNodeIn.read((char*)&outEL[0], sizeof(outEL[0]) * m);
neiWeightIn.read((char*)&outWEL[0], sizeof(outWEL[0]) * m);
neiNumIn.read((char*)&outPL[0], sizeof(outPL[0]) * (n + 1));
neiNumIn.close();
neiWeightIn.close();
neiNodeIn.close();
return;
}
void argParser(int argc, char** argv, string& filedir, string& filelabel, long& querynum, vector<double>& epss, uint& L, int& update)
// void argParser(int argc, char **argv, string &filedir, string &filelabel, long &querynum, double &eps, uint &L)
{
char* endptr;
int i = 1;
while (i < argc)
{
if (!strcmp(argv[i], "-d"))
{
if (++i < argc)
filedir = argv[i];
}
else if (!strcmp(argv[i], "-f"))
{
if (++i < argc)
filelabel = argv[i];
}
else if (!strcmp(argv[i], "-e"))
{
while (++i < argc && argv[i][0] != '-')
{
// eps = strtod(argv[++i], &endptr);
double eps = strtod(argv[i], &endptr);
epss.push_back(eps);
}
i--;
}
else if (!strcmp(argv[i], "-u"))
{
update = 1;
}
else if (!strcmp(argv[i], "-qn"))
{
if (++i < argc)
querynum = strtod(argv[i], &endptr);
if ((querynum < -2) && endptr)
{
cerr << "Invalid querynum argument:" << querynum << endl;
exit(1);
}
}
else if (!strcmp(argv[i], "-l"))
{
int tempL;
if (++i < argc)
tempL = int(strtod(argv[i], &endptr));
if ((tempL < 0) && endptr)
{
cerr << "Invalid hop number" << endl;
exit(1);
}
L = uint(tempL);
}
else
{
cerr << "Err args:" << argv[i] << endl;
exit(1);
}
i++;
}
}