-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmisc.cpp
More file actions
45 lines (40 loc) · 958 Bytes
/
Copy pathmisc.cpp
File metadata and controls
45 lines (40 loc) · 958 Bytes
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
#include "misc.hpp"
// reverse&complement a 0123-encoded string
void rc3(char *s, int l) {
int i;
for (i = 0; i < (l >> 1); ++i) {
int tmp = s[l - 1 - i];
s[l - 1 - i] = 4 - s[i];
s[i] = 4 - tmp;
}
if (l & 1)
s[i] = 4 - s[i];
}
// reverse&complement a 1234-encoded string
void rc4(char *s, int l) {
int i;
for (i = 0; i < (l >> 1); ++i) {
int tmp = s[l - 1 - i];
s[l - 1 - i] = 5 - s[i];
s[i] = 5 - tmp;
}
if (l & 1)
s[i] = 5 - s[i];
}
double realtime() {
struct timeval tp;
struct timezone tzp;
gettimeofday(&tp, &tzp);
return (double)tp.tv_sec + (double)tp.tv_usec * 1e-6;
}
long long current_rss_kb() {
std::ifstream f("/proc/self/status");
std::string line;
while (std::getline(f, line)) {
if (line.rfind("VmRSS:", 0) == 0) { // starts with "VmRSS:"
auto pos = line.find_first_of("0123456789");
return std::stoll(line.substr(pos)) / 1024 / 1024;
}
}
return -1;
}