Re: Problem with associative arrays

2011-03-20 Thread Jesse Phillips
Piotr Szturmaj Wrote: > Yes, I already used pointers but in other way: > > uint[]* temp = &aa[5]; // copy uint[] reference > > and it worked the same as using 'in'. However, I wasn't sure it's > completely safe. Depends on what you mean by "safe." In your example if 5 is not a key then a Rang

Re: Problem with associative arrays

2011-03-20 Thread Piotr Szturmaj
Jesse Phillips wrote: Piotr Szturmaj Wrote: Thank you for your very complete answers :) I was trying to avoid multiple AA key lookups while appending many elements to dynamic array. It's clear now, that with D2 semantics it's better to first build an array and then assign it to AA. What ever

Re: Problem with associative arrays

2011-03-19 Thread Jonathan M Davis
On Saturday 19 March 2011 11:12:49 Ali Çehreli wrote: > On 03/19/2011 10:05 AM, Mafi wrote: > > Am 19.03.2011 17:29, schrieb Piotr Szturmaj: > >> Shouldn't dynamic array be reference type? > > > > Just one note: appending (ar ~= 1) differs from concating (ar = ar ~ 1) > > that while the secon

Re: Problem with associative arrays

2011-03-19 Thread Jesse Phillips
Piotr Szturmaj Wrote: > Thank you for your very complete answers :) > > I was trying to avoid multiple AA key lookups while appending many > elements to dynamic array. It's clear now, that with D2 semantics it's > better to first build an array and then assign it to AA. What everyone else said

Re: Problem with associative arrays

2011-03-19 Thread Ali Çehreli
On 03/19/2011 10:05 AM, Mafi wrote: > Am 19.03.2011 17:29, schrieb Piotr Szturmaj: >> Shouldn't dynamic array be reference type? > Just one note: appending (ar ~= 1) differs from concating (ar = ar ~ 1) > that while the second is guanranteed to reallocate, about the first you > can't be sure. It

Re: Problem with associative arrays

2011-03-19 Thread Piotr Szturmaj
Thank you for your very complete answers :) I was trying to avoid multiple AA key lookups while appending many elements to dynamic array. It's clear now, that with D2 semantics it's better to first build an array and then assign it to AA.

Re: Problem with associative arrays

2011-03-19 Thread Mafi
Am 19.03.2011 17:29, schrieb Piotr Szturmaj: Shouldn't dynamic array be reference type? uint[][uint] aa; uint[] temp; aa[5] = new uint[0]; temp = aa[5]; // copy uint[] reference temp ~= 1; assert(temp.length == 1 && temp[0] == 1); // pass assert(aa[5].length == 1 && aa[5][0] == 1); // fail Is

Re: Problem with associative arrays

2011-03-19 Thread bearophile
Piotr Szturmaj: > Shouldn't dynamic array be reference type? They are partially a reference type and partially a value :-) A D dynamic array is represented with a small struct 2-words long that contains the pointer to the first item of the array and the length of the array (you are able to read

Problem with associative arrays

2011-03-19 Thread Piotr Szturmaj
Shouldn't dynamic array be reference type? uint[][uint] aa; uint[] temp; aa[5] = new uint[0]; temp = aa[5]; // copy uint[] reference temp ~= 1; assert(temp.length == 1 && temp[0] == 1); // pass assert(aa[5].length == 1 && aa[5][0] == 1); // fail Is this a bug?