-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.h
64 lines (58 loc) · 1.34 KB
/
common.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
#include <iostream>
#include <bits/stdc++.h>
#include <pthread.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <fstream>
#include <sstream>
#include <sys/stat.h>
#include <cmath>
#include <unistd.h>
#include <sys/file.h>
//#define _GNU_SOURCE
#include <fcntl.h>
#define BUFFER_SIZE 1024*64
#define QLIMIT 32
//#define CHUNK_SIZE 1024*512
#define CHUNK_SIZE 1024*64
using namespace std;
pair<string,int> split_address(string addr) {
int pos = addr.find(":");
pair<string,int> sock;
sock.first = addr.substr(0,pos);
sock.second = stoi(addr.substr(pos+1,addr.length()));
return sock;
}
vector<string> split_string(string s,char d) {
vector<string> v;
if(s=="") {
return v;
}
stringstream ss(s);
string temp;
while(getline(ss,temp,d)) {
v.push_back(temp);
}
return v;
}
vector<int> split_bitvector(string s,char d, int totchunks) {
vector<int> v;
v.resize(totchunks,0);
stringstream ss(s);
string temp;
while(getline(ss,temp,d)) {
v[stoi(temp)] = 1;
}
return v;
}
string bitvec_toString(vector<int> v) {
string bitstr = to_string(*v.begin());
for(auto it=v.begin();it!=v.end();it++) {
if(it == v.begin())
continue;
bitstr += ";"+to_string(*it);
}
return bitstr;
}