digitalmars.D.learn - How to clear associative array
- Zarathustra (5/5) Aug 01 2008 As in subject.
- Steven Schveighoffer (3/8) Aug 01 2008 array = null;
- BCS (5/13) Aug 01 2008 I'm not sure how array=null will interact with other references to the s...
- Steven Schveighoffer (6/17) Aug 01 2008 AA's are objects, so multiple references to the same AA would result in ...
- BCS (3/26) Aug 01 2008 void clear(T)(T toClear) {foreach(key; toClear.keys) toClear.remove(key)...
- Max Samukha (8/27) Aug 01 2008 It would be also nice to be able to initialize an AA reference without
As in subject. Type [KeyType] array; array[new KeyType(...)] = new Type(...); ... delete array; // error
Aug 01 2008
"Zarathustra"As in subject. Type [KeyType] array; array[new KeyType(...)] = new Type(...); ... delete array; // errorarray = null; -Steve
Aug 01 2008
Reply to Zarathustra,As in subject. Type [KeyType] array; array[new KeyType(...)] = new Type(...); ... delete array; // errorI'm not sure how array=null will interact with other references to the same AA. This should clear them as well (but is more costly). foreach(k;array.keys)array.delete(k);
Aug 01 2008
"BCS" wroteReply to Zarathustra,AA's are objects, so multiple references to the same AA would result in the data being retained for the references that you did not set to null. It would be nice to have a .clear function so you could deal with removing all elements when multiple references are used. -SteveAs in subject. Type [KeyType] array; array[new KeyType(...)] = new Type(...); ... delete array; // errorI'm not sure how array=null will interact with other references to the same AA.
Aug 01 2008
Reply to Steven,"BCS" wrotevoid clear(T)(T toClear) {foreach(key; toClear.keys) toClear.remove(key); } ?? O(n) (vs. O(1) for an internal version)Reply to Zarathustra,AA's are objects, so multiple references to the same AA would result in the data being retained for the references that you did not set to null. It would be nice to have a .clear function so you could deal with removing all elements when multiple references are used. -SteveAs in subject. Type [KeyType] array; array[new KeyType(...)] = new Type(...); ... delete array; // errorI'm not sure how array=null will interact with other references to the same AA.
Aug 01 2008
On Fri, 1 Aug 2008 15:47:35 -0400, "Steven Schveighoffer" <schveiguy yahoo.com> wrote:"BCS" wroteIt would be also nice to be able to initialize an AA reference without adding a value to the array. int[int] a; int[int] b = a; a[1] = 2; auto x = b[1]; // oopsReply to Zarathustra,AA's are objects, so multiple references to the same AA would result in the data being retained for the references that you did not set to null. It would be nice to have a .clear function so you could deal with removing all elements when multiple references are used. -SteveAs in subject. Type [KeyType] array; array[new KeyType(...)] = new Type(...); ... delete array; // errorI'm not sure how array=null will interact with other references to the same AA.
Aug 01 2008