00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef _CXSC_INTVECTOR_INL_INCLUDED
00027 #define _CXSC_INTVECTOR_INL_INCLUDED
00028
00029 #include "intvector.hpp"
00030
00031 namespace cxsc {
00032
00033 INLINE intvector::intvector () throw():dat(NULL),l(1),u(0),size(0)
00034 {
00035 }
00036
00037 INLINE intvector::intvector(const int &i) throw():l(1),u(i),size(i)
00038 {
00039 dat=new int[i];
00040 }
00041
00042 #ifdef OLD_CXSC
00043 INLINE intvector::intvector(const class index &i) throw():l(1),u(i._int()),size(i._int())
00044 {
00045 dat=new int[i._int()];
00046 }
00047 #endif
00048
00049 INLINE intvector::intvector(const int &i1,const int &i2)
00050 #if(CXSC_INDEX_CHECK)
00051 throw(ERROR_INTVECTOR_WRONG_BOUNDARIES,ERROR_INTVECTOR_NO_MORE_MEMORY):l(i1),u(i2),size(i2-i1+1)
00052 #else
00053 throw():l(i1),u(i2),size(i2-i1+1)
00054 #endif
00055 {
00056 #if(CXSC_INDEX_CHECK)
00057 if(i1>i2) cxscthrow(ERROR_INTVECTOR_WRONG_BOUNDARIES("intvector::intvector(const int &i1,const int &i2)"));
00058 #endif
00059 dat=new int[size];
00060 }
00061
00062 INLINE intvector::intvector(const intvector_slice &rs) throw():l(rs.start),u(rs.end),size(rs.end-rs.start+1)
00063 {
00064 dat=new int[size];
00065 for(int i=0, j=l-rs.l;i<size;i++,j++)
00066 dat[i]=rs.dat[j];
00067 }
00068
00069 INLINE intvector::intvector(const intvector &v) throw():l(v.l),u(v.u),size(v.size)
00070 {
00071 dat=new int[size];
00072 for (int i=0;i<size;i++)
00073 dat[i]=v.dat[i];
00074 }
00075
00076 INLINE int & intvector_slice::operator [](const int &i)
00077 #if(CXSC_INDEX_CHECK)
00078 throw(ERROR_INTVECTOR_ELEMENT_NOT_IN_VEC)
00079 #else
00080 throw()
00081 #endif
00082 {
00083 #if(CXSC_INDEX_CHECK)
00084 if(i<start||i>end) cxscthrow(ERROR_INTVECTOR_ELEMENT_NOT_IN_VEC("int & intvector_slice::operator [](const int &i)"));
00085 #endif
00086 return dat[i-l];
00087 }
00088
00089 INLINE const int & intvector_slice::operator [](const int &i) const
00090 #if(CXSC_INDEX_CHECK)
00091 throw(ERROR_INTVECTOR_ELEMENT_NOT_IN_VEC)
00092 #else
00093 throw()
00094 #endif
00095 {
00096 #if(CXSC_INDEX_CHECK)
00097 if(i<start||i>end) cxscthrow(ERROR_INTVECTOR_ELEMENT_NOT_IN_VEC("int & intvector_slice::operator [](const int &i)"));
00098 #endif
00099 return dat[i-l];
00100 }
00101
00102 INLINE const int & intvector::operator [](const int &i) const
00103 #if(CXSC_INDEX_CHECK)
00104 throw(ERROR_INTVECTOR_ELEMENT_NOT_IN_VEC)
00105 #else
00106 throw()
00107 #endif
00108 {
00109 #if(CXSC_INDEX_CHECK)
00110 if(i<l||i>u) cxscthrow(ERROR_INTVECTOR_ELEMENT_NOT_IN_VEC("int & intvector::operator [](const int &i)"));
00111 #endif
00112 return dat[i-l];
00113 }
00114
00115 INLINE int & intvector::operator [](const int &i)
00116 #if(CXSC_INDEX_CHECK)
00117 throw(ERROR_INTVECTOR_ELEMENT_NOT_IN_VEC)
00118 #else
00119 throw()
00120 #endif
00121 {
00122 #if(CXSC_INDEX_CHECK)
00123 if(i<l||i>u) cxscthrow(ERROR_INTVECTOR_ELEMENT_NOT_IN_VEC("int & intvector::operator [](const int &i)"));
00124 #endif
00125 return dat[i-l];
00126 }
00127
00134 INLINE intvector_slice intvector::operator ()(const int &i)
00135 #if(CXSC_INDEX_CHECK)
00136 throw(ERROR_INTVECTOR_SUB_ARRAY_TOO_BIG)
00137 #else
00138 throw()
00139 #endif
00140 {
00141 #if(CXSC_INDEX_CHECK)
00142 if(1<l||i>u) cxscthrow(ERROR_INTVECTOR_SUB_ARRAY_TOO_BIG("intvector_slice intvector::operator ()(const int &i)"));
00143 #endif
00144 return intvector_slice(*this,1,i);
00145 }
00146
00154 INLINE intvector_slice intvector::operator ()(const int &i1,const int &i2)
00155 #if(CXSC_INDEX_CHECK)
00156 throw(ERROR_INTVECTOR_SUB_ARRAY_TOO_BIG)
00157 #else
00158 throw()
00159 #endif
00160 {
00161 #if(CXSC_INDEX_CHECK)
00162 if(i1<l||i2>u) cxscthrow(ERROR_INTVECTOR_SUB_ARRAY_TOO_BIG("intvector_slice intvector::operator ()(const int &i1,const int &i2)"));
00163 #endif
00164 return intvector_slice(*this,i1,i2);
00165 }
00166
00167 INLINE intvector_slice intvector_slice::operator ()(const int &i)
00168 #if(CXSC_INDEX_CHECK)
00169 throw(ERROR_INTVECTOR_SUB_ARRAY_TOO_BIG)
00170 #else
00171 throw()
00172 #endif
00173 {
00174 #if(CXSC_INDEX_CHECK)
00175 if(1<start||i>end) cxscthrow(ERROR_INTVECTOR_SUB_ARRAY_TOO_BIG("intvector_slice intvector_slice::operator ()(const int &i)"));
00176 #endif
00177 return intvector_slice(*this,1,i);
00178 }
00179
00180 INLINE intvector_slice intvector_slice::operator ()(const int &i1,const int &i2)
00181 #if(CXSC_INDEX_CHECK)
00182 throw(ERROR_INTVECTOR_SUB_ARRAY_TOO_BIG)
00183 #else
00184 throw()
00185 #endif
00186 {
00187 #if(CXSC_INDEX_CHECK)
00188 if(i1<start||i2>end) cxscthrow(ERROR_INTVECTOR_SUB_ARRAY_TOO_BIG("intvector_slice intvector_slice::operator ()(const int &i1,const int &i2)"));
00189 #endif
00190 return intvector_slice(*this,i1,i2);
00191 }
00192
00193 INLINE intvector &intvector::operator =(const intvector &rv) throw() { return _vvassign<intvector,intvector,int>(*this,rv); }
00194 INLINE intvector &intvector::operator =(const int &r) throw() { return _vsassign<intvector,int>(*this,r); }
00195 INLINE intvector::operator void*() throw() { return _vvoid(*this); }
00196
00197 INLINE intvector_slice & intvector_slice::operator =(const intvector_slice &sl)
00198 #if(CXSC_INDEX_CHECK)
00199 throw(ERROR__OP_WITH_WRONG_DIM<intvector>)
00200 #else
00201 throw()
00202 #endif
00203 { return _vsvsassign<intvector_slice,intvector_slice>(*this,sl); }
00204 INLINE intvector_slice & intvector_slice::operator =(const intvector &rv)
00205 #if(CXSC_INDEX_CHECK)
00206 throw(ERROR__OP_WITH_WRONG_DIM<intvector>)
00207 #else
00208 throw()
00209 #endif
00210 { return _vsvassign<intvector_slice,intvector>(*this,rv); }
00211 INLINE intvector_slice & intvector_slice::operator =(const int &r) throw() { return _vssassign<intvector_slice,int>(*this,r); }
00212 INLINE intvector_slice::operator void*() throw() { return _vsvoid(*this); }
00213
00214
00220 INLINE intvector _intvector(const int &r) throw() { return intvector(r); }
00221
00222 INLINE void Resize(intvector &rv) throw() { _vresize(rv); }
00223 INLINE void Resize(intvector &rv, const int &len)
00224 #if(CXSC_INDEX_CHECK)
00225 throw(ERROR__WRONG_BOUNDARIES<intvector>)
00226 #else
00227 throw()
00228 #endif
00229 { _vresize<intvector,int>(rv,len); }
00230 INLINE void Resize(intvector &rv, const int &lb, const int &ub)
00231 #if(CXSC_INDEX_CHECK)
00232 throw(ERROR__WRONG_BOUNDARIES<intvector>)
00233 #else
00234 throw()
00235 #endif
00236 { _vresize<intvector,int>(rv,lb,ub); }
00237
00238 INLINE intvector abs(const intvector &rv) throw() { return _vabs<intvector,intvector>(rv); }
00239 INLINE intvector abs(const intvector_slice &sl) throw() { return _vsabs<intvector_slice,intvector>(sl); }
00240 INLINE bool operator !(const intvector &rv) throw() { return _vnot(rv); }
00241 INLINE bool operator !(const intvector_slice &sl) throw() { return _vsnot(sl); }
00242
00243
00244
00245 INLINE intvector operator *(const intvector &rv, const int &s) throw() { return _vsmult<intvector,int,intvector>(rv,s); }
00246 INLINE intvector operator *(const intvector_slice &sl, const int &s) throw() { return _vssmult<intvector_slice,int,intvector>(sl,s); }
00247 INLINE intvector operator *(const int &s, const intvector &rv) throw() { return _vsmult<intvector,int,intvector>(rv,s); }
00248 INLINE intvector operator *(const int &s, const intvector_slice &sl) throw() { return _vssmult<intvector_slice,int,intvector>(sl,s); }
00249 INLINE intvector &operator *=(intvector &rv,const int &r) throw() { return _vsmultassign(rv,r); }
00250 INLINE intvector_slice &intvector_slice::operator *=(const int &r) throw() { return _vssmultassign(*this,r); }
00251
00252 INLINE intvector operator /(const intvector &rv, const int &s) throw() { return _vsdiv<intvector,int,intvector>(rv,s); }
00253 INLINE intvector operator /(const intvector_slice &sl, const int &s) throw() { return _vssdiv<intvector_slice,int,intvector>(sl,s); }
00254 INLINE intvector &operator /=(intvector &rv,const int &r) throw() { return _vsdivassign(rv,r); }
00255 INLINE intvector_slice &intvector_slice::operator /=(const int &r) throw() { return _vssdivassign(*this,r); }
00256
00257
00258
00259 INLINE intvector &intvector::operator =(const intvector_slice &sl) throw() { return _vvsassign<intvector,intvector_slice,int>(*this,sl); }
00260
00261
00262 INLINE void accumulate(dotprecision &dp, const intvector & rv1, const intvector &rv2)
00263 #if(CXSC_INDEX_CHECK)
00264 throw(OP_WITH_WRONG_DIM)
00265 #else
00266 throw()
00267 #endif
00268 { _vvaccu(dp,rv1,rv2); }
00269
00270
00271 INLINE void accumulate(dotprecision &dp,const intvector_slice &sl,const intvector &rv)
00272 #if(CXSC_INDEX_CHECK)
00273 throw(OP_WITH_WRONG_DIM)
00274 #else
00275 throw()
00276 #endif
00277 { _vsvaccu(dp,sl,rv); }
00278 INLINE void accumulate(dotprecision &dp,const intvector &rv,const intvector_slice &sl)
00279 #if(CXSC_INDEX_CHECK)
00280 throw(OP_WITH_WRONG_DIM)
00281 #else
00282 throw()
00283 #endif
00284 { _vsvaccu(dp,sl,rv); }
00285 INLINE void accumulate(dotprecision &dp, const intvector_slice & sl1, const intvector_slice &sl2)
00286 #if(CXSC_INDEX_CHECK)
00287 throw(OP_WITH_WRONG_DIM)
00288 #else
00289 throw()
00290 #endif
00291 { _vsvsaccu(dp,sl1,sl2); }
00292
00293 INLINE const intvector &operator +(const intvector &rv) throw() { return rv; }
00294 INLINE intvector operator +(const intvector_slice &sl) throw() { return sl; }
00295 INLINE intvector operator +(const intvector &rv1, const intvector &rv2)
00296 #if(CXSC_INDEX_CHECK)
00297 throw(ERROR__OP_WITH_WRONG_DIM<intvector>)
00298 #else
00299 throw()
00300 #endif
00301 { return _vvplus<intvector,intvector,intvector>(rv1,rv2); }
00302 INLINE intvector operator +(const intvector &rv, const intvector_slice &sl)
00303 #if(CXSC_INDEX_CHECK)
00304 throw(ERROR__OP_WITH_WRONG_DIM<intvector>)
00305 #else
00306 throw()
00307 #endif
00308 { return _vvsplus<intvector,intvector_slice,intvector>(rv,sl); }
00309 INLINE intvector operator +(const intvector_slice &sl, const intvector &rv)
00310 #if(CXSC_INDEX_CHECK)
00311 throw(ERROR__OP_WITH_WRONG_DIM<intvector>)
00312 #else
00313 throw()
00314 #endif
00315 { return _vvsplus<intvector,intvector_slice,intvector>(rv,sl); }
00316 INLINE intvector operator +(const intvector_slice &sl1, const intvector_slice &sl2)
00317 #if(CXSC_INDEX_CHECK)
00318 throw(ERROR__OP_WITH_WRONG_DIM<intvector>)
00319 #else
00320 throw()
00321 #endif
00322 { return _vsvsplus<intvector_slice,intvector_slice,intvector>(sl1,sl2); }
00323 INLINE intvector & operator +=(intvector &rv1, const intvector &rv2)
00324 #if(CXSC_INDEX_CHECK)
00325 throw(ERROR__OP_WITH_WRONG_DIM<intvector>)
00326 #else
00327 throw()
00328 #endif
00329 { return _vvplusassign(rv1,rv2); }
00330 INLINE intvector &operator +=(intvector &rv, const intvector_slice &sl)
00331 #if(CXSC_INDEX_CHECK)
00332 throw(ERROR__OP_WITH_WRONG_DIM<intvector>)
00333 #else
00334 throw()
00335 #endif
00336 { return _vvsplusassign(rv,sl); }
00337 INLINE intvector_slice &intvector_slice::operator +=(const intvector &rv)
00338 #if(CXSC_INDEX_CHECK)
00339 throw(ERROR__OP_WITH_WRONG_DIM<intvector>)
00340 #else
00341 throw()
00342 #endif
00343 { return _vsvplusassign(*this,rv); }
00344 INLINE intvector_slice &intvector_slice::operator +=(const intvector_slice &sl2)
00345 #if(CXSC_INDEX_CHECK)
00346 throw(ERROR__OP_WITH_WRONG_DIM<intvector>)
00347 #else
00348 throw()
00349 #endif
00350 { return _vsvsplusassign(*this,sl2); }
00351
00352 INLINE intvector operator -(const intvector &rv) throw() { return _vminus(rv); }
00353 INLINE intvector operator -(const intvector_slice &sl) throw() { return _vsminus<intvector_slice,intvector>(sl); }
00354 INLINE intvector operator -(const intvector &rv1, const intvector &rv2)
00355 #if(CXSC_INDEX_CHECK)
00356 throw(ERROR__OP_WITH_WRONG_DIM<intvector>)
00357 #else
00358 throw()
00359 #endif
00360 { return _vvminus<intvector,intvector,intvector>(rv1,rv2); }
00361 INLINE intvector operator -(const intvector &rv, const intvector_slice &sl)
00362 #if(CXSC_INDEX_CHECK)
00363 throw(ERROR__OP_WITH_WRONG_DIM<intvector>)
00364 #else
00365 throw()
00366 #endif
00367 { return _vvsminus<intvector,intvector_slice,intvector>(rv,sl); }
00368 INLINE intvector operator -(const intvector_slice &sl, const intvector &rv)
00369 #if(CXSC_INDEX_CHECK)
00370 throw(ERROR__OP_WITH_WRONG_DIM<intvector>)
00371 #else
00372 throw()
00373 #endif
00374 { return _vsvminus<intvector_slice,intvector,intvector>(sl,rv); }
00375 INLINE intvector operator -(const intvector_slice &sl1, const intvector_slice &sl2)
00376 #if(CXSC_INDEX_CHECK)
00377 throw(ERROR__OP_WITH_WRONG_DIM<intvector>)
00378 #else
00379 throw()
00380 #endif
00381 { return _vsvsminus<intvector_slice,intvector_slice,intvector>(sl1,sl2); }
00382 INLINE intvector & operator -=(intvector &rv1, const intvector &rv2)
00383 #if(CXSC_INDEX_CHECK)
00384 throw(ERROR__OP_WITH_WRONG_DIM<intvector>)
00385 #else
00386 throw()
00387 #endif
00388 { return _vvminusassign(rv1,rv2); }
00389 INLINE intvector &operator -=(intvector &rv, const intvector_slice &sl)
00390 #if(CXSC_INDEX_CHECK)
00391 throw(ERROR__OP_WITH_WRONG_DIM<intvector>)
00392 #else
00393 throw()
00394 #endif
00395 { return _vvsminusassign(rv,sl); }
00396 INLINE intvector_slice &intvector_slice::operator -=(const intvector &rv)
00397 #if(CXSC_INDEX_CHECK)
00398 throw(ERROR__OP_WITH_WRONG_DIM<intvector>)
00399 #else
00400 throw()
00401 #endif
00402 { return _vsvminusassign(*this,rv); }
00403 INLINE intvector_slice &intvector_slice::operator -=(const intvector_slice &sl2)
00404 #if(CXSC_INDEX_CHECK)
00405 throw(ERROR__OP_WITH_WRONG_DIM<intvector>)
00406 #else
00407 throw()
00408 #endif
00409 { return _vsvsminusassign(*this,sl2); }
00410
00411 INLINE bool operator ==(const intvector &rv1, const intvector &rv2) throw() { return _vveq(rv1,rv2); }
00412 INLINE bool operator ==(const intvector_slice &sl1, const intvector_slice &sl2) throw() { return _vsvseq(sl1,sl2); }
00413 INLINE bool operator ==(const intvector_slice &sl, const intvector &rv) throw() { return _vsveq(sl,rv); }
00414 INLINE bool operator ==(const intvector &rv, const intvector_slice &sl) throw() { return _vsveq(sl,rv); }
00415 INLINE bool operator !=(const intvector &rv1, const intvector &rv2) throw() { return _vvneq(rv1,rv2); }
00416 INLINE bool operator !=(const intvector_slice &sl1, const intvector_slice &sl2) throw() { return _vsvsneq(sl1,sl2); }
00417 INLINE bool operator !=(const intvector_slice &sl, const intvector &rv) throw() { return _vsvneq(sl,rv); }
00418 INLINE bool operator !=(const intvector &rv, const intvector_slice &sl) throw() { return _vsvneq(sl,rv); }
00419 INLINE bool operator <(const intvector &rv1, const intvector &rv2) throw() { return _vvless(rv1,rv2); }
00420 INLINE bool operator <(const intvector_slice &sl1, const intvector_slice &sl2) throw() { return _vsvsless(sl1,sl2); }
00421 INLINE bool operator < (const intvector_slice &sl, const intvector &rv) throw() { return _vsvless(sl,rv); }
00422 INLINE bool operator < (const intvector &rv, const intvector_slice &sl) throw() { return _vvsless(rv,sl); }
00423 INLINE bool operator <=(const intvector &rv1, const intvector &rv2) throw() { return _vvleq(rv1,rv2); }
00424 INLINE bool operator <=(const intvector_slice &sl1, const intvector_slice &sl2) throw() { return _vsvsleq(sl1,sl2); }
00425 INLINE bool operator <=(const intvector_slice &sl, const intvector &rv) throw() { return _vsvleq(sl,rv); }
00426 INLINE bool operator <=(const intvector &rv, const intvector_slice &sl) throw() { return _vvsleq(rv,sl); }
00427 INLINE bool operator >(const intvector &rv1, const intvector &rv2) throw() { return _vvless(rv2,rv1); }
00428 INLINE bool operator >(const intvector_slice &sl1, const intvector_slice &sl2) throw() { return _vsvsless(sl2,sl1); }
00429 INLINE bool operator >(const intvector_slice &sl, const intvector &rv) throw() { return _vvsless(rv,sl); }
00430 INLINE bool operator >(const intvector &rv, const intvector_slice &sl) throw() { return _vsvless(sl,rv); }
00431 INLINE bool operator >=(const intvector &rv1, const intvector &rv2) throw() { return _vvleq(rv2,rv1); }
00432 INLINE bool operator >=(const intvector_slice &sl1, const intvector_slice &sl2) throw() { return _vsvsleq(sl2,sl1); }
00433 INLINE bool operator >=(const intvector_slice &sl, const intvector &rv) throw() { return _vvsleq(rv,sl); }
00434 INLINE bool operator >=(const intvector &rv, const intvector_slice &sl) throw() { return _vsvleq(sl,rv); }
00435
00436 INLINE std::ostream &operator <<(std::ostream &s, const intvector &rv) throw() { return _vout(s,rv); }
00437 INLINE std::ostream &operator <<(std::ostream &o, const intvector_slice &sl) throw() { return _vsout(o,sl); }
00438 INLINE std::istream &operator >>(std::istream &s, intvector &rv) throw() { return _vin(s,rv); }
00439 INLINE std::istream &operator >>(std::istream &s, intvector_slice &rv) throw() { return _vsin(s,rv); }
00440
00441 INLINE intvector perminv(const intvector& x) {
00442 intvector p(0,VecLen(x));
00443 for(int i=0 ; i<VecLen(x) ; i++)
00444 p[x[i+Lb(x)]] = i;
00445 return p;
00446 }
00447
00448
00449 }
00450
00451 #endif
00452