C-XSC - A C++ Class Library for Extended Scientific Computing 2.5.4
lx_ivector.inl
1/*
2** CXSC is a C++ library for eXtended Scientific Computing (V 2.5.4)
3**
4** Copyright (C) 1990-2000 Institut fuer Angewandte Mathematik,
5** Universitaet Karlsruhe, Germany
6** (C) 2000-2014 Wiss. Rechnen/Softwaretechnologie
7** Universitaet Wuppertal, Germany
8**
9** This library is free software; you can redistribute it and/or
10** modify it under the terms of the GNU Library General Public
11** License as published by the Free Software Foundation; either
12** version 2 of the License, or (at your option) any later version.
13**
14** This library is distributed in the hope that it will be useful,
15** but WITHOUT ANY WARRANTY; without even the implied warranty of
16** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17** Library General Public License for more details.
18**
19** You should have received a copy of the GNU Library General Public
20** License along with this library; if not, write to the Free
21** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22*/
23
24/* CVS $Id: lx_ivector.inl,v 1.9 2014/01/30 17:23:47 cxsc Exp $ */
25
26namespace cxsc {
27
31 inline lx_ivector::lx_ivector () noexcept:dat(NULL),l(1),u(0),size(0)
32 { }
33
39 inline lx_ivector::lx_ivector(int i) noexcept:l(1),u(i),size(i)
40 {
41 dat=new lx_interval[i];
42 }
43
50 inline lx_ivector::lx_ivector(int i1, int i2)
51#if(CXSC_INDEX_CHECK)
52 :
53 l(i1),u(i2),size(i2-i1+1)
54#else
55 noexcept:l(i1),u(i2),size(i2-i1+1)
56#endif
57 {
58#if(CXSC_INDEX_CHECK)
59 if(i1>i2) cxscthrow(ERROR_IVECTOR_WRONG_BOUNDARIES(
60 "lx_ivector(const int &i1,const int &i2)"));
61#endif
62 dat=new lx_interval[size];
63 }
64
65 inline lx_ivector::lx_ivector(const lx_interval &r) noexcept:l(1),u(1),size(1)
66 {
67 dat=new lx_interval[1];
68 *dat=r;
69 }
70
71 inline lx_ivector::lx_ivector(const l_interval &r) noexcept:l(1),u(1),size(1)
72 {
73 dat=new lx_interval[1];
74 *dat=r;
75 }
76
77 inline lx_ivector::lx_ivector(const interval &r) noexcept:l(1),u(1),size(1)
78 {
79 dat=new lx_interval[1];
80 *dat=r;
81 }
82
83 inline lx_ivector::lx_ivector(const lx_real &r) noexcept:l(1),u(1),size(1)
84 {
85 dat=new lx_interval[1];
86 *dat=r;
87 }
88
89 inline lx_ivector::lx_ivector(const l_real &r) noexcept:l(1),u(1),size(1)
90 {
91 dat=new lx_interval[1];
92 *dat=r;
93 }
94
95 inline lx_ivector::lx_ivector(const real &r) noexcept:l(1),u(1),size(1)
96 {
97 dat=new lx_interval[1];
98 *dat=r;
99 }
100
102 noexcept:l(v.l),u(v.u),size(v.size)
103 {
104 dat=new lx_interval[size];
105 for (int i=0;i<size;i++)
106 dat[i]=v.dat[i];
107 }
108
109 inline lx_ivector &lx_ivector::operator =(const lx_ivector &rv) noexcept
110 {
111 l = rv.l; u = rv.u; size = rv.size;
112 dat=new lx_interval[size];
113 for (int i=0;i<size;i++)
114 dat[i]=rv.dat[i];
115 return *this;
116 }
117
118 inline lx_ivector &lx_ivector::operator =(const lx_interval &r) noexcept
119 {
120 lx_interval *newdat = new lx_interval[size];
121 for (int i=0;i<size;i++)
122 newdat[i] = r;
123 delete [] dat;
124 dat = newdat;
125 return *this;
126 }
127
129 {
130 lx_interval *newdat = new lx_interval[size];
131 for (int i=0;i<size;i++)
132 newdat[i] = r;
133 delete [] dat;
134 dat = newdat;
135 return *this;
136 }
137
138 inline lx_ivector &lx_ivector::operator =(const interval &r) noexcept
139 {
140 lx_interval *newdat = new lx_interval[size];
141 for (int i=0;i<size;i++)
142 newdat[i] = r;
143 delete [] dat;
144 dat = newdat;
145 return *this;
146 }
147
148 inline lx_ivector &lx_ivector::operator =(const lx_real &r) noexcept
149 {
150 lx_interval *newdat = new lx_interval[size];
151 for (int i=0;i<size;i++)
152 newdat[i] = r;
153 delete [] dat;
154 dat = newdat;
155 return *this;
156 }
157
158 inline lx_ivector &lx_ivector::operator =(const l_real &r) noexcept
159 {
160 lx_interval *newdat = new lx_interval[size];
161 for (int i=0;i<size;i++)
162 newdat[i] = r;
163 delete [] dat;
164 dat = newdat;
165 return *this;
166 }
167
168 inline lx_ivector &lx_ivector::operator =(const real &r) noexcept
169 {
170 lx_interval *newdat = new lx_interval[size];
171 for (int i=0;i<size;i++)
172 newdat[i] = r;
173 delete [] dat;
174 dat = newdat;
175 return *this;
176 }
177
178 inline lx_interval & lx_ivector::operator [](const int &i)
179#if(CXSC_INDEX_CHECK)
180
181#else
182 noexcept
183#endif
184 {
185#if(CXSC_INDEX_CHECK)
186 if(i<l||i>u) cxscthrow(ERROR_IVECTOR_ELEMENT_NOT_IN_VEC(
187 "lx_interval & lx_ivector::operator [](const int &i)"));
188#endif
189 return dat[i-l];
190 }
191
192 inline const lx_interval & lx_ivector::operator [](const int &i) const
193#if(CXSC_INDEX_CHECK)
194
195#else
196 noexcept
197#endif
198 {
199#if(CXSC_INDEX_CHECK)
200 if(i<l || i>u) cxscthrow(ERROR_IVECTOR_ELEMENT_NOT_IN_VEC(
201 "lx_interval & lx_ivector::operator [](const int &i)"));
202#endif
203 return dat[i-l];
204 }
205
206inline void Resize(lx_ivector &rv, int len)
207#if(CXSC_INDEX_CHECK)
208 ;
209#else
210 noexcept
211#endif
212 {
213 if (rv.size == len)
214 SetLb(rv,1);
215 else
216 {
217#if(CXSC_INDEX_CHECK)
218 if (len<0)
219 cxscthrow(ERROR__WRONG_BOUNDARIES(
220 "Resize(lx_ivector &rv, int len)"));
221#endif
222 lx_interval *ndat = new lx_interval[len];
223 int beg, end;
224 beg = (rv.l>1)? rv.l : 1;
225 end = (rv.u<len)? rv.u : len;
226 for(int i=beg-1;i<end;i++)
227 ndat[i]=rv.dat[i-rv.l+1];
228 delete [] rv.dat;
229 rv.dat=ndat;
230 rv.size=rv.u=len;
231 rv.l=1;
232 }
233 }
234
235inline void Resize(lx_ivector &rv, int lb, int ub)
236#if(CXSC_INDEX_CHECK)
237
238#else
239 noexcept
240#endif
241{
242 if (rv.size == ub-lb+1)
243 SetUb(rv,ub);
244 else
245 {
246 rv.size = ub-lb+1;
247#if(CXSC_INDEX_CHECK)
248 if (rv.size<0)
249 cxscthrow(ERROR__WRONG_BOUNDARIES(
250 "Resize(lx_ivector &rv, int lb, int ub)"));
251#endif
252 lx_interval *ndat = new lx_interval[rv.size];
253 int beg, end;
254 beg = (rv.l>lb)? rv.l : lb;
255 end = (rv.u<ub)? rv.u : ub;
256 for(int i=0;i<=rv.size-1;i++)
257 ndat[i]=interval(0);
258 for(int i=beg;i<=end;i++)
259 ndat[i-lb]=rv.dat[i-rv.l];
260 delete [] rv.dat;
261 rv.dat=ndat;
262 rv.l=lb;
263 rv.u=ub;
264 }
265}
266
267inline void DoubleSize(lx_ivector& x) noexcept
268{
269 int n = Lb(x);
270 Resize(x,n,2*Ub(x)-n+1);
271}
272
273} // namespace cxsc
The Scalar Type interval.
Definition interval.hpp:55
The Multiple-Precision Data Type l_interval.
The Multiple-Precision Data Type l_real.
Definition l_real.hpp:78
The Multiple-Precision Data Type lx_ivector.
lx_ivector & operator=(const lx_ivector &) noexcept
Implementation of standard assigning operator.
lx_interval & operator[](const int &i) noexcept
Operator for accessing the single elements of the vector.
lx_ivector() noexcept
Constructor of class lx_ivector.
The Scalar Type real.
Definition real.hpp:114
The namespace cxsc, providing all functionality of the class library C-XSC.
Definition cdot.cpp:29
int Ub(const cimatrix &rm, const int &i) noexcept
Returns the upper bound index.
cimatrix & SetLb(cimatrix &m, const int &i, const int &j) noexcept
Sets the lower bound index.
void DoubleSize(cimatrix &A)
Doubles the size of the matrix.
Definition cimatrix.cpp:83
void Resize(cimatrix &A) noexcept
Resizes the matrix.
cimatrix & SetUb(cimatrix &m, const int &i, const int &j) noexcept
Sets the upper bound index.
int Lb(const cimatrix &rm, const int &i) noexcept
Returns the lower bound index.