www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - how can I empty associative arrays?

reply razvanaciu rdstm.ro writes:
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
Jun 18 2004
next sibling parent Ben Hinkle <bhinkle4 juno.com> writes:
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
Jun 18 2004
prev sibling parent reply Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
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
Jun 18 2004
parent reply Ilya Minkov <minkov cs.tum.edu> writes:
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
Jun 18 2004
parent Regan Heath <regan netwin.co.nz> writes:
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/
Jun 18 2004