Re: How i can clear Associative Arrays

2013-04-28 Thread Marco Leise
Am Mon, 15 Apr 2013 13:06:01 -0400 schrieb "Steven Schveighoffer" : > On Sun, 14 Apr 2013 02:50:07 -0400, gedaiu wrote: > > > On Saturday, 13 April 2013 at 21:10:16 UTC, Nicolas Guillemot wrote: > >>> I think we should introduce a removeAll function for hashes. Either > >>> through Druntime or t

Re: How i can clear Associative Arrays

2013-04-15 Thread Michael
On Monday, 15 April 2013 at 11:36:55 UTC, Tobias Pankrath wrote: You could set the length to 0. Before version 4.0 in C# a Clear extension-method just calls Collection.length = 0; Later this method was included to BCL. In D length property for AA is readonly.

Re: How i can clear Associative Arrays

2013-04-15 Thread Steven Schveighoffer
On Sun, 14 Apr 2013 02:50:07 -0400, gedaiu wrote: On Saturday, 13 April 2013 at 21:10:16 UTC, Nicolas Guillemot wrote: I think we should introduce a removeAll function for hashes. Either through Druntime or through a UFCS function that we could put in std.array or somewhere. How about .clear

Re: How i can clear Associative Arrays

2013-04-15 Thread Andrea Fontana
Not on associative arrays afaik. On Monday, 15 April 2013 at 11:36:55 UTC, Tobias Pankrath wrote: You could set the length to 0.

Re: How i can clear Associative Arrays

2013-04-15 Thread Tobias Pankrath
You could set the length to 0.

Re: How i can clear Associative Arrays

2013-04-15 Thread Andrea Fontana
On Sunday, 14 April 2013 at 06:50:08 UTC, gedaiu wrote: On Saturday, 13 April 2013 at 21:10:16 UTC, Nicolas Guillemot wrote: I think we should introduce a removeAll function for hashes. Either through Druntime or through a UFCS function that we could put in std.array or somewhere. How about

Re: How i can clear Associative Arrays

2013-04-13 Thread gedaiu
On Saturday, 13 April 2013 at 21:10:16 UTC, Nicolas Guillemot wrote: I think we should introduce a removeAll function for hashes. Either through Druntime or through a UFCS function that we could put in std.array or somewhere. How about .clear() for consistency with C++ containers? It looks

Re: How i can clear Associative Arrays

2013-04-13 Thread Nicolas Guillemot
I think we should introduce a removeAll function for hashes. Either through Druntime or through a UFCS function that we could put in std.array or somewhere. How about .clear() for consistency with C++ containers?

Re: How i can clear Associative Arrays

2013-04-13 Thread Andrej Mitrovic
On 4/13/13, gedaiu wrote: > I know, that's why I am asking how i should do this... I think we should introduce a removeAll function for hashes. Either through Druntime or through a UFCS function that we could put in std.array or somewhere. Putting it in Druntime is probably the most efficient wa

Re: How i can clear Associative Arrays

2013-04-13 Thread gedaiu
On Saturday, 13 April 2013 at 09:52:45 UTC, Andrej Mitrovic wrote: On 4/13/13, gedaiu wrote: looks great, but i cleared the array like this: values = null; That's not clearing the array, that's clearing the reference to the array. For example: void main() { int[int] hash; hash[1]

Re: How i can clear Associative Arrays

2013-04-13 Thread Andrej Mitrovic
On 4/13/13, gedaiu wrote: > looks great, but i cleared the array like this: > > values = null; That's not clearing the array, that's clearing the reference to the array. For example: void main() { int[int] hash; hash[1] = 1; auto hash2 = hash; // new reference hash = null; //

Re: How i can clear Associative Arrays

2013-04-13 Thread Nicolas Guillemot
values = null; and it seems it works great. But, i don't know how correct is this... I was expecting to have a clear() method on array. Makes sense to me! Looks like the technique you described is explained here: http://ddili.org/ders/d.en/null_is.html Good find, thanks for sharing!

Re: How i can clear Associative Arrays

2013-04-13 Thread gedaiu
On Saturday, 13 April 2013 at 09:09:36 UTC, Nicolas Guillemot wrote: Hey gedaiu, I'm still a novice to D, but here are some solutions I found. They can probably be improved. 1) Assigning to it an empty map https://ideone.com/h7ffmD 2) Removing all entries https://ideone.com/E7k2WL My guess

Re: How i can clear Associative Arrays

2013-04-13 Thread Nicolas Guillemot
Hey gedaiu, I'm still a novice to D, but here are some solutions I found. They can probably be improved. 1) Assigning to it an empty map https://ideone.com/h7ffmD 2) Removing all entries https://ideone.com/E7k2WL My guess is that the first method is more efficient. I wish I knew how to do i

How i can clear Associative Arrays

2013-04-13 Thread gedaiu
Hi, I have an associative array: string values[string], and i want to remove all the values from this array. I looked at the documentation here: http://dlang.org/hash-map.html and i can't see any method for this action. There is a nice way to remove the values, or I should use foreach? Than