Thread overview
how can I empty associative arrays?
Jun 18, 2004
razvanaciu
Jun 18, 2004
Ben Hinkle
Jun 18, 2004
Russ Lewis
Jun 18, 2004
Ilya Minkov
Jun 18, 2004
Regan Heath
June 18, 2004
how can I empty associative arrays of form

char[][char[]] a;

because
a.length=0
is not allowed
and
a=new char[][char[]]
is also not allowed :)

Thank you,
Razvan


June 18, 2004
razvanaciu@rdstm.ro wrote:

> how can I empty associative arrays of form
> 
> char[][char[]] a;
> 
> because
> a.length=0
> is not allowed
> and
> a=new char[][char[]]
> is also not allowed :)
> 
> Thank you,
> Razvan

This is implementation-dependent, but

 a = null;

works. If you want to preserve the size of the hashtable, do something like

 void*[] b = cast(void*[])a;
 b[] = null;

-Ben
June 18, 2004
It would be cool if there were an automatic way to do it, but I don't know of any.  However, this code should work:

foreach(char[] key; a.keys)
  delete a[key];  // removes it from the hash, doesn't delete the thing



razvanaciu@rdstm.ro wrote:
> how can I empty associative arrays of form
> 
> char[][char[]] a;
> 
> because
> a.length=0 is not allowed
> and
> a=new char[][char[]]
> is also not allowed :)
> 
> Thank you,
> Razvan

June 18, 2004
Russ Lewis schrieb:
> It would be cool if there were an automatic way to do it, but I don't know of any. 

How about something like "b = b.init"?

> However, this code should work:
> 
> foreach(char[] key; a.keys)
>   delete a[key];  // removes it from the hash, doesn't delete the thing

Bleah, i don't like it.

-eye
June 18, 2004
On Fri, 18 Jun 2004 22:04:45 +0200, Ilya Minkov <minkov@cs.tum.edu> wrote:

> Russ Lewis schrieb:
>> It would be cool if there were an automatic way to do it, but I don't know of any.
>
> How about something like "b = b.init"?

This seems to work, however does it free the hash table? (length == 0 after this call)

>> However, this code should work:
>>
>> foreach(char[] key; a.keys)
>>   delete a[key];  // removes it from the hash, doesn't delete the thing
>
> Bleah, i don't like it.

Neither, it seems in-efficient.

Regan

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/