00001
00002 #include <MC_int_vector.hpp>
00003 #include <MC_string_helper.hpp>
00004 #include <MC_int_pair.hpp>
00005
00006
00007 namespace mesh_conv
00008 {
00009
00010
00011 MC_int_vector::MC_int_vector(){}
00012
00013 MC_int_vector::MC_int_vector(const int& u0)
00014 {int_list.push_back(u0);}
00015 MC_int_vector::MC_int_vector(const int& u0,const int& u1){int_list.push_back(u0);int_list.push_back(u1);}
00016 MC_int_vector::MC_int_vector(const int& u0,const int& u1,const int& u2){int_list.push_back(u0);int_list.push_back(u1);int_list.push_back(u2);}
00017 MC_int_vector::MC_int_vector(const int& u0,const int& u1,const int& u2,const int& u3){int_list.push_back(u0);int_list.push_back(u1);int_list.push_back(u2);int_list.push_back(u3);}
00018 MC_int_vector::MC_int_vector(const int& u0,const int& u1,const int& u2,const int& u3,const int& u4){int_list.push_back(u0);int_list.push_back(u1);int_list.push_back(u2);int_list.push_back(u3);int_list.push_back(u4);}
00019 MC_int_vector::MC_int_vector(const int& u0,const int& u1,const int& u2,const int& u3,const int& u4,const int& u5){int_list.push_back(u0);int_list.push_back(u1);int_list.push_back(u2);int_list.push_back(u3);int_list.push_back(u4);int_list.push_back(u5);}
00020
00021 void MC_int_vector::assert_bounds(const int& u) const
00022 {
00023 if(u<0 || u>=int(int_list.size()))
00024 {std::cout<<"Assert mesh_conv::MC_int_vector::assert_bounds("<<u<<") failed, because size="<<int_list.size()<<std::endl;exit(-1);}
00025 }
00026
00027 int MC_int_vector::size() const
00028 {return int_list.size();}
00029
00030 const int& MC_int_vector::operator()(const int& index) const
00031 {assert_bounds(index); return int_list[index];}
00032 int& MC_int_vector::operator()(const int& index)
00033 {assert_bounds(index); return int_list[index];}
00034 const int& MC_int_vector::operator[](const int& index) const
00035 {assert_bounds(index); return int_list[index];}
00036 int& MC_int_vector::operator[](const int& index)
00037 {assert_bounds(index); return int_list[index];}
00038
00039 void MC_int_vector::clear()
00040 {int_list.clear();}
00041
00042
00043
00044 std::ostream& operator<<(std::ostream& output,const MC_int_vector& in)
00045 {
00046 int N=in.size();
00047 for(int k=0;k<N;k++)
00048 output<<in[k]<<" ";
00049 return output;
00050 }
00051
00052 MC_int_vector::MC_int_vector(const std::string& in,const std::string& delimiter)
00053 {
00054 std::vector <std::string> v_string=MC_string_tokenizer::tokenize(in,delimiter);
00055 bool is_converted=false;
00056 for(unsigned int k=0;k<v_string.size();k++)
00057 {
00058 int value=MC_string_converter::value_of<int>(v_string[k],&is_converted);
00059 if(is_converted==true)
00060 add(value);
00061 }
00062 }
00063
00064
00065 MC_int_vector& MC_int_vector::add(const int& val)
00066 {int_list.push_back(val);return *this;}
00067
00068 MC_int_vector operator<<(const MC_int_vector& vec,const int& value)
00069 {return MC_int_vector(vec).add(value);}
00070
00071
00072 MC_int_vector& MC_int_vector::add(const MC_int_vector& val)
00073 {
00074 int N=val.size();
00075 int end=int_list.size();
00076 int_list.resize(int_list.size()+N);
00077 for(int k=0;k<N;++k)
00078 int_list[end+k]=val[k];
00079 return *this;
00080 }
00081
00082 std::vector <int>& MC_int_vector::get_vector() {return int_list;}
00083 const std::vector <int>& MC_int_vector::to_vector() const {return int_list;}
00084
00085
00086 std::set <int> MC_int_vector::to_set() const
00087 {
00088 std::set <int> set_int;
00089 set_int.insert(int_list.begin(),int_list.end());
00090 return set_int;
00091 }
00092 std::map <int,int> MC_int_vector::to_map() const
00093 {
00094 std::map <int,int> map_int;
00095 int N=size();
00096 for(int k=0;k<N;k++)
00097 map_int.insert(std::pair<int,int>(this->operator()(k),k));
00098 return map_int;
00099 }
00100
00101 mesh_conv::MC_int_vector operator<<(const mesh_conv::MC_int_vector& vec,const mesh_conv::MC_int_vector& to_add)
00102 {return MC_int_vector(vec).add(to_add);}
00103
00104 MC_int_vector& MC_int_vector::set(const int& k_index,const int& new_value)
00105 {
00106 if(k_index<0)
00107 {std::cout<<"Error in MC_int_vector::set("<<k_index<<","<<new_value<<"), index must be >0"<<std::endl;exit(-1);}
00108 if(k_index>=size())
00109 int_list.resize(k_index+1);
00110 int_list[k_index]=new_value;
00111 return *this;
00112 }
00113
00114 MC_int_vector& MC_int_vector::set(const MC_int_vector& k_index,const MC_int_vector& new_value)
00115 {
00116 MC_int_vector v_new_value=new_value;
00117 if(new_value.size()!=1 && new_value.size()!=k_index.size())
00118 {std::cout<<"Error in MC_int_vector::set(MC_int_vector,MC_int_vector), size are not correct: "<<k_index.size()<<","<<new_value.size()<<std::endl;exit(-1);}
00119 if(new_value.size()==1)
00120 v_new_value=MC_int_vector::zeros(k_index.size())+new_value;
00121
00122
00123 int N=v_new_value.size();
00124 for(int k=0;k<N;k++)
00125 set(k_index[k],v_new_value[k]);
00126 return *this;
00127 }
00128
00129
00130 MC_int_vector::MC_int_vector(const std::set <int>& vec)
00131 {
00132 for(std::set <int> :: const_iterator it=vec.begin();it!=vec.end();++it)
00133 int_list.push_back(*it);
00134 }
00135 MC_int_vector::MC_int_vector(const std::map <int,int> &vec)
00136 {
00137 for(std::map <int,int> :: const_iterator it=vec.begin();it!=vec.end();++it)
00138 set(it->second,it->first);
00139 }
00140 MC_int_vector::MC_int_vector(const std::vector <int> &vec)
00141 {
00142 int_list=vec;
00143 }
00144 MC_int_vector::MC_int_vector(const MC_int_vector& vec)
00145 {
00146 int_list=vec.to_vector();
00147 }
00148
00149 MC_int_vector MC_int_vector::zeros(const int& new_size)
00150 {
00151 MC_int_vector vec;vec.resize(new_size);
00152 return vec;
00153 }
00154
00155 MC_int_vector MC_int_vector::linspace(const int& begin,const int& end,const double& iteration)
00156 {
00157 MC_int_vector temp;
00158 double d_begin=static_cast<double>(begin);
00159 double d_end=static_cast<double>(end);
00160
00161 if(d_end>=d_begin && iteration>0)
00162 {
00163 for(double u=d_begin;u<=d_end;u+=iteration)
00164 temp.add(static_cast<int>(u));
00165 }
00166 else if(iteration<0)
00167 {
00168 for(double u=d_begin;u>=d_end;u+=iteration)
00169 temp.add(static_cast<int>(u));
00170 }
00171 else
00172 {std::cout<<"Error in MC_int_vector::linspace("<<begin<<","<<end<<","<<iteration<<"), parameters will infinitely loop"<<std::endl;exit(-1);}
00173
00174 return temp;
00175 }
00176
00177
00178 MC_int_vector& MC_int_vector::resize(const int& new_size)
00179 {
00180 int N=int_list.size();
00181 if(N==new_size)
00182 return *this;
00183
00184 if(new_size<0)
00185 {std::cout<<"Error in MC_int_vector::resize("<<new_size<<") new size must be >0"<<std::endl;exit(-1);}
00186
00187 int_list.resize(new_size);
00188 return *this;
00189
00190 }
00191 MC_int_vector MC_int_vector::operator-() const
00192 {
00193 MC_int_vector opposite;
00194 int N=size();
00195 opposite.resize(N);
00196 for(int k=0;k<N;++k)
00197 opposite[k]=-int_list[k];
00198 return opposite;
00199 }
00200
00201 MC_int_vector operator+(const MC_int_vector& vec,const int& to_add)
00202 {
00203 int N=vec.size();
00204 MC_int_vector new_vec=MC_int_vector::zeros(N);
00205 for(int k=0;k<N;k++)
00206 new_vec[k]=vec[k]+to_add;
00207 return new_vec;
00208 }
00209 MC_int_vector operator-(const MC_int_vector& vec,const int& to_sub)
00210 {
00211 int N=vec.size();
00212 MC_int_vector new_vec=MC_int_vector::zeros(N);
00213 for(int k=0;k<N;k++)
00214 new_vec[k]=vec[k]-to_sub;
00215 return new_vec;
00216 }
00217 MC_int_vector operator*(const MC_int_vector& vec,const int& to_mult)
00218 {
00219 int N=vec.size();
00220 MC_int_vector new_vec=MC_int_vector::zeros(N);
00221 for(int k=0;k<N;k++)
00222 new_vec[k]=vec[k]*to_mult;
00223 return new_vec;
00224 }
00225 MC_int_vector operator/(const MC_int_vector& vec,const int& to_subdiv)
00226 {
00227 if(to_subdiv==0)
00228 {std::cout<<"Error in MC_int_vector::operator/(MC_int_vector,int), int value is 0"<<std::endl;exit(-1);}
00229 int N=vec.size();
00230 MC_int_vector new_vec=MC_int_vector::zeros(N);
00231 for(int k=0;k<N;k++)
00232 new_vec[k]=vec[k]/to_subdiv;
00233 return new_vec;
00234 }
00235
00236 MC_int_vector& MC_int_vector::operator+=(const int& to_add)
00237 {
00238 int N=size();
00239 for(int k=0;k<N;++k)
00240 int_list[k]+=to_add;
00241 return *this;
00242 }
00243 MC_int_vector& MC_int_vector::operator-=(const int& to_sub)
00244 {
00245 int N=size();
00246 for(int k=0;k<N;++k)
00247 int_list[k]-=to_sub;
00248 return *this;
00249 }
00250 MC_int_vector& MC_int_vector::operator*=(const int& to_mult)
00251 {
00252 int N=size();
00253 for(int k=0;k<N;++k)
00254 int_list[k]*=to_mult;
00255 return *this;
00256 }
00257 MC_int_vector& MC_int_vector::operator/=(const int& to_subdiv)
00258 {
00259 if(to_subdiv==0)
00260 {std::cout<<"Error in MC_int_vector::operator/=(int), int value is 0"<<std::endl;exit(-1);}
00261 int N=size();
00262 for(int k=0;k<N;++k)
00263 int_list[k]/=to_subdiv;
00264 return *this;
00265 }
00266
00267
00268 MC_int_vector operator+(const MC_int_vector& vec,const MC_int_vector& to_add)
00269 {
00270 if(to_add.size()==1)
00271 return vec+to_add.first();
00272 else if(vec.size()==1)
00273 return to_add+static_cast<int>(vec.first());
00274 else
00275 {
00276 if(vec.size()!=to_add.size())
00277 {std::cout<<"Error in MC_int_vector::operator+(MC_int_vector,MC_int_vector), size are not compatible "<<vec.size()<<";"<<to_add.size()<<std::endl;exit(-1);}
00278
00279
00280 int N=vec.size();
00281 MC_int_vector new_vec=MC_int_vector::zeros(N);
00282 for(int k=0;k<N;++k)
00283 new_vec[k]=vec[k]+to_add[k];
00284 return new_vec;
00285 }
00286 }
00287 MC_int_vector operator-(const MC_int_vector& vec,const MC_int_vector& to_sub)
00288 {
00289 if(to_sub.size()==1)
00290 return vec-to_sub.first();
00291 else
00292 {
00293 if(vec.size()!=to_sub.size())
00294 {std::cout<<"Error in MC_int_vector::operator-(MC_int_vector,MC_int_vector), size are not compatible "<<vec.size()<<";"<<to_sub.size()<<std::endl;exit(-1);}
00295
00296
00297 int N=vec.size();
00298 MC_int_vector new_vec=MC_int_vector::zeros(N);
00299 for(int k=0;k<N;++k)
00300 new_vec[k]=vec[k]-to_sub[k];
00301 return new_vec;
00302 }
00303 }
00304 MC_int_vector operator*(const MC_int_vector& vec,const MC_int_vector& to_mult)
00305 {
00306 if(to_mult.size()==1)
00307 return vec*to_mult.first();
00308 else
00309 {
00310 if(vec.size()!=to_mult.size())
00311 {std::cout<<"Error in MC_int_vector::operator*(MC_int_vector,MC_int_vector), size are not compatible "<<vec.size()<<";"<<to_mult.size()<<std::endl;exit(-1);}
00312
00313
00314 int N=vec.size();
00315 MC_int_vector new_vec=MC_int_vector::zeros(N);
00316 for(int k=0;k<N;++k)
00317 new_vec[k]=vec[k]*to_mult[k];
00318 return new_vec;
00319 }
00320 }
00321 MC_int_vector operator/(const MC_int_vector& vec,const MC_int_vector& to_subdiv)
00322 {
00323 if(to_subdiv.size()==1)
00324 return vec/to_subdiv.first();
00325 else
00326 {
00327 if(vec.size()!=to_subdiv.size())
00328 {std::cout<<"Error in MC_int_vector::operator/(MC_int_vector,MC_int_vector), size are not compatible "<<vec.size()<<";"<<to_subdiv.size()<<std::endl;exit(-1);}
00329
00330
00331 int N=vec.size();
00332 MC_int_vector new_vec=MC_int_vector::zeros(N);
00333 for(int k=0;k<N;++k)
00334 {
00335 int current=to_subdiv[k];
00336 if(current==0)
00337 {std::cout<<"Error in MC_int_vector::operator/(MC_int_vector,MC_int_vector), int value at index"<<k<<" is 0"<<std::endl;exit(-1);}
00338 new_vec[k]=vec[k]/current;
00339 }
00340 return new_vec;
00341 }
00342
00343 }
00344
00345
00346 MC_int_vector& MC_int_vector::operator+=(const MC_int_vector& to_add)
00347 {
00348 if(to_add.size()==1)
00349 return *this+=to_add.first();
00350 else
00351 {
00352 if(size()!=to_add.size())
00353 {std::cout<<"Error in MC_int_vector::operator+=(MC_int_vector), size are not compatible "<<size()<<";"<<to_add.size()<<std::endl;exit(-1);}
00354
00355 int N=size();
00356 for(int k=0;k<N;++k)
00357 int_list[k]+=to_add[k];
00358 return *this;
00359 }
00360 }
00361 MC_int_vector& MC_int_vector::operator-=(const MC_int_vector& to_sub)
00362 {
00363 if(to_sub.size()==1)
00364 return *this-=to_sub.first();
00365 else
00366 {
00367 if(size()!=to_sub.size())
00368 {std::cout<<"Error in MC_int_vector::operator-=(MC_int_vector), size are not compatible "<<size()<<";"<<to_sub.size()<<std::endl;exit(-1);}
00369
00370 int N=size();
00371 for(int k=0;k<N;++k)
00372 int_list[k]-=to_sub[k];
00373 return *this;
00374 }
00375
00376 }
00377 MC_int_vector& MC_int_vector::operator*=(const MC_int_vector& to_mult)
00378 {
00379 if(to_mult.size()==1)
00380 return *this*=to_mult.first();
00381 else
00382 {
00383 if(size()!=to_mult.size())
00384 {std::cout<<"Error in MC_int_vector::operator*=(MC_int_vector), size are not compatible "<<size()<<";"<<to_mult.size()<<std::endl;exit(-1);}
00385
00386 int N=size();
00387 for(int k=0;k<N;++k)
00388 int_list[k]*=to_mult[k];
00389 return *this;
00390 }
00391 }
00392 MC_int_vector& MC_int_vector::operator/=(const MC_int_vector& to_subdiv)
00393 {
00394 if(to_subdiv.size()==1)
00395 return *this/=to_subdiv.first();
00396 else
00397 {
00398 if(size()!=to_subdiv.size())
00399 {std::cout<<"Error in MC_int_vector::operator/=(MC_int_vector), size are not compatible "<<size()<<";"<<to_subdiv.size()<<std::endl;exit(-1);}
00400
00401 int N=size();
00402 for(int k=0;k<N;++k)
00403 {
00404 int current=to_subdiv[k];
00405 if(current==0)
00406 {std::cout<<"Error in MC_int_vector::operator/=(MC_int_vector), try do divide by u["<<k<<"]=0"<<std::endl;exit(-1);}
00407 int_list[k]*=current;
00408 }
00409 return *this;
00410 }
00411 }
00412
00413 const int& MC_int_vector::first() const
00414 {
00415 if(size()>0)
00416 return int_list[0];
00417 else
00418 {
00419 std::cout<<"Error, call MC_int_vector::first() with size=0"<<std::endl;exit(-1);
00420 exit(-1);
00421 }
00422 }
00423 int& MC_int_vector::first()
00424 {
00425 if(size()>0)
00426 return int_list[0];
00427 else
00428 {
00429 std::cout<<"Error, call MC_int_vector::first() with size=0"<<std::endl;exit(-1);
00430 exit(-1);
00431 }
00432 }
00433 const int& MC_int_vector::last() const
00434 {
00435 if(size()>0)
00436 return int_list[size()-1];
00437 else
00438 {
00439 std::cout<<"Error, call MC_int_vector::last() with size=0"<<std::endl;exit(-1);
00440 }
00441 }
00442 int& MC_int_vector::last()
00443 {
00444 if(size()>0)
00445 return int_list[size()-1];
00446 else
00447 {
00448 std::cout<<"Error, call MC_int_vector::last() with size=0"<<std::endl;exit(-1);
00449 }
00450 }
00451
00452 std::pair <MC_int_vector,int> MC_int_vector::delete_index(const int& index_to_delete) const
00453 {
00454 if(index_to_delete<0 || index_to_delete>=size())
00455 {std::cout<<"Error in MC_int_vector::delete("<<index_to_delete<<", when size="<<size()<<std::endl;exit(-1);}
00456 MC_int_vector new_vec;
00457 int N=size();
00458 for(int k=0;k<N;++k)
00459 if(k!=index_to_delete)
00460 new_vec.add(int_list[k]);
00461 return std::pair <MC_int_vector,int>(new_vec,int_list[index_to_delete]);
00462 }
00463 std::pair <MC_int_vector,MC_int_vector> MC_int_vector::delete_index(const MC_int_vector& index_to_delete) const
00464 {
00465 std::set <int> set_index=index_to_delete.to_set();
00466 MC_int_vector new_vec;
00467 MC_int_vector deleted_vec;
00468 int N=size();
00469 for(int k=0;k<N;k++)
00470 {
00471 if(set_index.find(k)!=set_index.end())
00472 new_vec.add(int_list[k]);
00473 else
00474 deleted_vec.add(int_list[k]);
00475 }
00476 return std::pair <MC_int_vector,MC_int_vector> (new_vec,deleted_vec);
00477 }
00478
00479 MC_int_vector MC_int_vector::operator()(const MC_int_vector& index) const
00480 {
00481 int N=size();
00482 int N2=index.size();
00483 MC_int_vector new_vec=zeros(N2);
00484 for(int k=0;k<N2;++k)
00485 {
00486 if(index[k]<0 || index[k]>N)
00487 {std::cout<<"Error in MC_int_vector::operator()(MC_int_vector), value index["<<k<<"]="<<index[k]<<" not correct for size="<<N<<std::endl;exit(-1);}
00488 new_vec[k]=int_list[index[k]];
00489 }
00490 return new_vec;
00491 }
00492 MC_int_vector MC_int_vector::operator[](const MC_int_vector& index) const
00493 {return (*this)(index);}
00494
00495
00496 mesh_conv::MC_int_vector& operator>>(std::istream& input,mesh_conv::MC_int_vector& vec)
00497 {
00498 while(input.good())
00499 {
00500 int temp=0;
00501 input>>temp;
00502 if(input.good())
00503 vec.add(temp);
00504 }
00505 return vec;
00506 }
00507
00508
00509 MC_int_vector operator<(const MC_int_vector& vec,const int& val)
00510 {
00511 int N=vec.size();
00512 MC_int_vector res=MC_int_vector::zeros(N);
00513 for(int k=0;k<N;k++)
00514 if(vec[k]<val)
00515 res[k]=1;
00516 return res;
00517 }
00518 MC_int_vector operator<=(const MC_int_vector& vec,const int& val)
00519 {
00520 int N=vec.size();
00521 MC_int_vector res=MC_int_vector::zeros(N);
00522 for(int k=0;k<N;k++)
00523 if(vec[k]<=val)
00524 res[k]=1;
00525 return res;
00526 }
00527 MC_int_vector operator>(const MC_int_vector& vec,const int& val)
00528 {
00529 int N=vec.size();
00530 MC_int_vector res=MC_int_vector::zeros(N);
00531 for(int k=0;k<N;k++)
00532 if(vec[k]>val)
00533 res[k]=1;
00534 return res;
00535 }
00536 MC_int_vector operator>=(const MC_int_vector& vec,const int& val)
00537 {
00538 int N=vec.size();
00539 MC_int_vector res=MC_int_vector::zeros(N);
00540 for(int k=0;k<N;k++)
00541 if(vec[k]>=val)
00542 res[k]=1;
00543 return res;
00544 }
00545 MC_int_vector operator==(const MC_int_vector& vec,const int& val)
00546 {
00547 int N=vec.size();
00548 MC_int_vector res=MC_int_vector::zeros(N);
00549 for(int k=0;k<N;k++)
00550 if(vec[k]==val)
00551 res[k]=1;
00552 return res;
00553 }
00554
00555 MC_int_vector operator<(const int& val,const MC_int_vector& vec)
00556 {return vec>val;}
00557 MC_int_vector operator<=(const int& val,const MC_int_vector& vec)
00558 {return vec>=val;}
00559 MC_int_vector operator>(const int& val,const MC_int_vector& vec)
00560 {return vec<val;}
00561 MC_int_vector operator>=(const int& val,const MC_int_vector& vec)
00562 {return vec<=val;}
00563 MC_int_vector operator==(const int& val,const MC_int_vector& vec)
00564 {return vec==val;}
00565 const int* MC_int_vector::pointer() const {return &int_list[0];}
00566
00567 std::list <MC_int_vector> MC_int_vector::connected_component(const std::set<MC_int_pair,MC_int_pair_less>& pair_set)
00568 {
00569 std::list <MC_int_vector> full;
00570
00571
00572 std::list <MC_int_pair> list_pair;
00573 for(std::set <MC_int_pair,MC_int_pair_less>::iterator it=pair_set.begin();it!=pair_set.end();++it)
00574 list_pair.push_back(*it);
00575
00576
00577
00578
00579
00580 std::list <MC_int_pair> :: iterator it;
00581 std::list <int> current_curve;
00582
00583
00584 while(list_pair.size()>0)
00585 {
00586
00587 it=list_pair.begin();
00588 int to_find=(*it)[1];
00589 current_curve.push_back( (*it)[0] );
00590 current_curve.push_back( to_find );
00591 list_pair.erase(it);
00592
00593
00594 bool find_next=true;
00595 while(find_next==true)
00596 {
00597 find_next=false;
00598 std::list<MC_int_pair>::iterator searcher;
00599
00600
00601 for(searcher=list_pair.begin();searcher!=list_pair.end();++searcher)
00602 {
00603 if( (*searcher)[0]==to_find )
00604 {
00605 current_curve.push_back( (*searcher)[1] );
00606 to_find=(*searcher)[1];
00607 break;
00608 }
00609 else if((*searcher)[1]==to_find )
00610 {
00611 current_curve.push_back( (*searcher)[0] );
00612 to_find=(*searcher)[0];
00613 break;
00614 }
00615 }
00616 if(searcher!=list_pair.end())
00617 {
00618 list_pair.erase(searcher);
00619 find_next=true;
00620 }
00621 }
00622
00623
00624
00625
00626
00627
00628
00629
00630 full.push_back(MC_int_vector(current_curve));
00631 current_curve.clear();
00632
00633 }
00634
00635 return full;
00636 }
00637
00638 MC_int_vector::MC_int_vector(const std::list <int> &vec)
00639 {
00640 for(std::list <int>::const_iterator it=vec.begin();it!=vec.end();++it)
00641 add(*it);
00642 }
00643 std::list <int> MC_int_vector::to_list() const
00644 {
00645 std::list <int> index;
00646 int N=size();
00647 for(int k=0;k<N;++k)
00648 index.push_back(int_list[k]);
00649 return index;
00650 }
00651
00652 int MC_int_vector::find(const int& to_find) const
00653 {
00654 int N=size();
00655 for(int k=0;k<N;++k)
00656 if(to_find==int_list[k])
00657 return k;
00658 return -1;
00659 }
00660
00665 std::pair <MC_int_vector,MC_int_vector> MC_int_vector::sort() const
00666 {
00667
00668 int N=size();
00669 std::vector <std::pair<int,int> > vec_to_sort(N);
00670 for(int k=0;k<N;++k)
00671 vec_to_sort[k]=std::pair <int,int>(int_list[k],k);
00672
00673
00674 std::sort(vec_to_sort.begin(),
00675 vec_to_sort.end(),
00676 comparator_less_int_int());
00677
00678
00679 std::pair <MC_int_vector,MC_int_vector> res;
00680 res.first.resize(N);res.second.resize(N);
00681 for(int k=0;k<N;++k)
00682 {
00683 res.first[k]=vec_to_sort[k].first;
00684 res.second[k]=vec_to_sort[k].second;
00685 }
00686 return res;
00687 }
00688
00689 MC_int_vector& MC_int_vector::erase_last()
00690 {resize(size()-1);return *this;}
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702 MC_int_vector MC_int_vector::mapping(const std::map<int,int> map_to_apply) const
00703 {
00704 std::map <int,int> :: const_iterator it_end=map_to_apply.end();
00705 std::map <int,int> :: const_iterator it;
00706
00707 int N=size();
00708 MC_int_vector mapped_value=MC_int_vector::zeros(N);
00709 for(int k=0;k<N;++k)
00710 {
00711 int current_index=int_list[k];
00712 it=map_to_apply.find(current_index);
00713 if(it==it_end)
00714 mapped_value[k]=-1;
00715 else
00716 mapped_value[k]=it->second;
00717 }
00718 return mapped_value;
00719 }
00720
00721 MC_int_vector MC_int_vector::inverted() const
00722 {
00723 unsigned int N=size();
00724 MC_int_vector inv=MC_int_vector::zeros(N);
00725 for(int k=0;k<N;++k)
00726 inv[k]=int_list[N-k-1];
00727 return inv;
00728 }
00729 MC_int_vector::MC_int_vector(const std::set <unsigned int>& vec)
00730 {
00731 for(std::set<unsigned int>::const_iterator it=vec.begin(),it_end=vec.end();it!=it_end;++it)
00732 add(*it);
00733 }
00734 MC_v3d MC_int_vector::to_v3d() const
00735 {return MC_v3d(int_list[0],int_list[1],int_list[2]);}
00736
00737 }