Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
June 18, 2004 how can I empty associative arrays? | ||||
---|---|---|---|---|
| ||||
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 Re: how can I empty associative arrays? | ||||
---|---|---|---|---|
| ||||
Posted in reply to razvanaciu | 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 Re: how can I empty associative arrays? | ||||
---|---|---|---|---|
| ||||
Posted in reply to razvanaciu | 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 Re: how can I empty associative arrays? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russ Lewis | 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 Re: how can I empty associative arrays? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Minkov | 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/ |
Copyright © 1999-2021 by the D Language Foundation