comparison dmd/Array.d @ 84:be2ab491772e

Expressions -> Vector!Expression
author Eldar Insafutdinov <e.insafutdinov@gmail.com>
date Mon, 30 Aug 2010 16:12:19 +0100
parents ad4792a1cfd6
children 39648eb578f6
comparison
equal deleted inserted replaced
83:ee670dd808a8 84:be2ab491772e
187 @property final size_t dim() 187 @property final size_t dim()
188 { 188 {
189 return _dim; 189 return _dim;
190 } 190 }
191 191
192 @property final void dim(size_t newDim)
193 {
194 _dim = newDim;
195 }
196
192 @property final size_t length() const 197 @property final size_t length() const
193 { 198 {
194 return _dim; 199 return _dim;
195 } 200 }
196 /* Doesn't work due to compiler BUG 201 /* Doesn't work due to compiler BUG
197 @property final size_t opDollar() const 202 @property final size_t opDollar() const
198 { 203 {
199 return _dim; 204 return _dim;
200 } 205 }
201 */ 206 */
202 /* 207
203 @property T *data() 208 @property T *data()
204 { 209 {
205 return _data; 210 return _data;
206 } 211 }
207 */ 212
208 @property final size_t allocdim() 213 @property final size_t allocdim()
209 { 214 {
210 return _allocdim; 215 return _allocdim;
211 } 216 }
212 217
213 T opIndex(size_t index) 218 ref T opIndex(size_t index)
214 { 219 {
215 return _data[index]; 220 return _data[index];
216 } 221 }
217 222
218 void opIndexAssign(T value, size_t index) 223 void opIndexAssign(T value, size_t index)
221 } 226 }
222 227
223 final T pop() 228 final T pop()
224 { 229 {
225 T v = _data[--_dim]; 230 T v = _data[--_dim];
226 _data[dim] = T.init; 231 // _data[dim] = T.init;
227 return v; 232 return v;
228 } 233 }
229 234
230 final void push(T elem) 235 final void push(T elem)
231 { 236 {
268 if (dim < newdim) { 273 if (dim < newdim) {
269 reserve(newdim - dim); 274 reserve(newdim - dim);
270 } 275 }
271 276
272 _dim = newdim; 277 _dim = newdim;
278 // TODO if newdim < dim set memory to T.init
273 } 279 }
274 280
275 int opApply(scope int delegate(ref T) dg) 281 int opApply(scope int delegate(ref T) dg)
276 { 282 {
277 int result = 0; 283 int result = 0;
300 final void append(Vector!T a) 306 final void append(Vector!T a)
301 { 307 {
302 insert(dim, a); 308 insert(dim, a);
303 } 309 }
304 310
311 final void remove(size_t i)
312 {
313 memmove(_data + i, _data + i + 1, (_dim - i) * T.sizeof);
314 // _data[dim-1] = T.init;
315 _dim--;
316 }
317
318 final void insert(uint index, T ptr)
319 {
320 reserve(1);
321 memmove(_data + index + 1, _data + index, (_dim - index) * T.sizeof);
322 _data[index] = ptr;
323 _dim++;
324 }
325
305 final void insert(size_t index, Vector!T a) 326 final void insert(size_t index, Vector!T a)
306 { 327 {
307 if (a !is null) { 328 if (a !is null) {
308 uint d = a.dim; 329 uint d = a.dim;
309 reserve(d); 330 reserve(d);