-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic_operations.h
156 lines (106 loc) · 2.41 KB
/
basic_operations.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
#ifndef GAURD_basic_operations
#define GAURD_basic_operations
//using namespace std;
template<class T>
std::ostream& operator<<(std::ostream &out,const std::vector<T> &V){
using namespace std;
if(V.size() > 0){
for(size_t i(0);i<V.size()-1;++i)
out<<V[i]<<",";
out<<V[V.size()-1];
}
return out;
}
template<class T>
std::ostream& operator<<(std::ostream &out,const std::vector<std::vector<T> > &V){
using namespace std;
for(int i(0);i<V.size();++i)
out<<V[i]<<"\n";
return out;
}
template<class T>
std::ostream & operator << (std::ostream & out, const thrust::device_vector<T> & V) {
for(int i(0);i<V.size()-1;++i)
out<<V[i]<<",";
out<<V[V.size()-1];
return out;
}
template<class T>
std::ostream & operator << (std::ostream & out, const thrust::host_vector<T> & V) {
for(int i(0);i<V.size()-1;++i)
out<<V[i]<<",";
out<<V[V.size()-1];
return out;
}
std::vector<std::string> split(const std::string& line){
std::vector<std::string> split_string;
std::string::const_iterator i(line.begin()),j(line.begin());
while(i!=line.end() && j!=line.end()){
while(isspace(*i) && i!=line.end())
++i;
j=i;
while(!isspace(*j) && j!=line.end())
++j;
std::string word(i,j);
if(word.length()>0)
split_string.push_back(word);
i=j;
}
return split_string;
}
std::vector<std::string> split(const std::string & line,const std::string & S) {
using namespace std;
vector<string> ans;
const size_t L( S.size() );
string::const_iterator i(line.begin()),j1(line.begin()),j2(line.begin() + L);
while(i != line.end()){
{
const string temp(i,line.end());
if(temp.size() < L){
ans.push_back(temp);
return ans;
}
}
j1 = i;
j2 = j1+L;
string val(j1,j2);
while(val != S && j2 != line.end()){
++j1;
j2 = j1+L;
val = string(j1,j2);
}
if(val == S){
string temp(i,j1);
ans.push_back(temp);
}
else{
string temp(i,line.end());
ans.push_back(temp);
return ans;
}
if(j2 == line.end()){
ans.push_back("");
return ans;
}
i = j2;
}
return ans;
}
std::string myitoa(int CHROM) {
using namespace std;
string sign("");
if(CHROM < 0) {
sign = "-";
CHROM = -CHROM;
}
string val("");
while(CHROM > 0) {
const int rem(CHROM % 10);
const string temp(1, '0'+rem);
val = temp + val;
CHROM /= 10;
}
val = sign + val;
return val;
}
#endif