digitalmars.D - how can I empty associative arrays?
- razvanaciu rdstm.ro (10/10) Jun 18 2004 how can I empty associative arrays of form
- Ben Hinkle (7/20) Jun 18 2004 This is implementation-dependent, but
- Russ Lewis (5/18) Jun 18 2004 It would be cool if there were an automatic way to do it, but I don't
- Ilya Minkov (4/10) Jun 18 2004 Bleah, i don't like it.
- Regan Heath (7/16) Jun 18 2004 This seems to work, however does it free the hash table? (length == 0
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
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, RazvanThis 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
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
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 thingBleah, i don't like it. -eye
Jun 18 2004
On Fri, 18 Jun 2004 22:04:45 +0200, Ilya Minkov <minkov cs.tum.edu> wrote:Russ Lewis schrieb:This seems to work, however does it free the hash table? (length == 0 after this call)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"?Neither, it seems in-efficient. Regan -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/However, this code should work: foreach(char[] key; a.keys) delete a[key]; // removes it from the hash, doesn't delete the thingBleah, i don't like it.
Jun 18 2004