digitalmars.D.learn - (1.0) Clearing out an Associative Array
- jicman (7/7) Jan 28 2008 Greetings.
- Bjoern (20/33) Jan 28 2008 To clear an AA
- Steven Schveighoffer (5/15) Jan 28 2008 How about
- Bill Baxter (3/30) Jan 28 2008 I think =null works for both too.
- jicman (3/28) Jan 28 2008 Thanks Steve. This one worked.
- Bill Baxter (6/33) Jan 29 2008 Are you implying that
- Steven Schveighoffer (4/37) Jan 31 2008 Ha ha! jicman liked my idea better. Jealous much?
- bearophile (15/17) Jan 31 2008 Try this:
- jicman (2/35) Feb 01 2008 No, I just tried the .init and it worked and that is what I wanted. .-)
Greetings. Long time no write. :-) I know that I can get the keys of an Associative array and do a foreach loop and remove the keys of the array, but is there an easier and quicker way? I know that I can set any non-Associative array to [], ie, myArr = []; and that is sufficient or set the length to 0; but how about the Associative arrays? Is there a quick way of doing this? thanks, josé
Jan 28 2008
jicman schrieb:Greetings. Long time no write. :-) I know that I can get the keys of an Associative array and do a foreach loop and remove the keys of the array, but is there an easier and quicker way? I know that I can set any non-Associative array to [], ie, myArr = []; and that is sufficient or set the length to 0; but how about the Associative arrays? Is there a quick way of doing this? thanks, joséTo clear an AA // some Associative Array properties bool hasData(T,E)(T[E] aa) { return aa.length > 0; } // by Ben Hinkle private struct BB { void*[]b; size_t nodes; } private union ToPtr(T) {T x; void * ptr; } void clear(T,E)(T[E] aa) { ToPtr!(typeof(aa)) toptr; toptr.x = aa; BB* b = cast(BB*) toptr.ptr; if (b) { b.b = null; b.nodes = 0; } } aa.clear() //D 1.x If you mean, clearing just the keys, sorry dunno Bjoern
Jan 28 2008
"jicman" wroteGreetings. Long time no write. :-) I know that I can get the keys of an Associative array and do a foreach loop and remove the keys of the array, but is there an easier and quicker way? I know that I can set any non-Associative array to [], ie, myArr = []; and that is sufficient or set the length to 0; but how about the Associative arrays? Is there a quick way of doing this? thanks, joséHow about myArr = myArr.init; Works for both associative and standard arrays -Steve
Jan 28 2008
Steven Schveighoffer wrote:"jicman" wroteI think =null works for both too. --bbGreetings. Long time no write. :-) I know that I can get the keys of an Associative array and do a foreach loop and remove the keys of the array, but is there an easier and quicker way? I know that I can set any non-Associative array to [], ie, myArr = []; and that is sufficient or set the length to 0; but how about the Associative arrays? Is there a quick way of doing this? thanks, joséHow about myArr = myArr.init; Works for both associative and standard arrays -Steve
Jan 28 2008
Steven Schveighoffer Wrote:"jicman" wroteThanks Steve. This one worked. joséGreetings. Long time no write. :-) I know that I can get the keys of an Associative array and do a foreach loop and remove the keys of the array, but is there an easier and quicker way? I know that I can set any non-Associative array to [], ie, myArr = []; and that is sufficient or set the length to 0; but how about the Associative arrays? Is there a quick way of doing this? thanks, joséHow about myArr = myArr.init; Works for both associative and standard arrays
Jan 28 2008
jicman wrote:Steven Schveighoffer Wrote:Are you implying that myArr=null; did not work? because it should. And it's less typing. And avoids you having to repeat yourself. :-) --bb"jicman" wroteThanks Steve. This one worked.Greetings. Long time no write. :-) I know that I can get the keys of an Associative array and do a foreach loop and remove the keys of the array, but is there an easier and quicker way? I know that I can set any non-Associative array to [], ie, myArr = []; and that is sufficient or set the length to 0; but how about the Associative arrays? Is there a quick way of doing this? thanks, joséHow about myArr = myArr.init; Works for both associative and standard arrays
Jan 29 2008
"Bill Baxter" wrotejicman wrote:Ha ha! jicman liked my idea better. Jealous much? j/k, I like your solution better :) -SteveSteven Schveighoffer Wrote:Are you implying that myArr=null; did not work? because it should. And it's less typing. And avoids you having to repeat yourself. :-)"jicman" wroteThanks Steve. This one worked.Greetings. Long time no write. :-) I know that I can get the keys of an Associative array and do a foreach loop and remove the keys of the array, but is there an easier and quicker way? I know that I can set any non-Associative array to [], ie, myArr = []; and that is sufficient or set the length to 0; but how about the Associative arrays? Is there a quick way of doing this? thanks, joséHow about myArr = myArr.init; Works for both associative and standard arrays
Jan 31 2008
Steven Schveighoffer:Ha ha! jicman liked my idea better. Jealous much? j/k, I like your solution better :)Try this: import std.stdio; void main() { int[int] a = [10:20, 30:40]; auto b = a; writefln(a, " ", b); a = null; writefln(a, " ", b); } It outputs: [10:20,30:40] [10:20,30:40] [] [10:20,30:40] Bye, bearophile
Jan 31 2008
Bill Baxter Wrote:jicman wrote:No, I just tried the .init and it worked and that is what I wanted. .-)Steven Schveighoffer Wrote:Are you implying that myArr=null; did not work? because it should. And it's less typing. And avoids you having to repeat yourself. :-)"jicman" wroteThanks Steve. This one worked.Greetings. Long time no write. :-) I know that I can get the keys of an Associative array and do a foreach loop and remove the keys of the array, but is there an easier and quicker way? I know that I can set any non-Associative array to [], ie, myArr = []; and that is sufficient or set the length to 0; but how about the Associative arrays? Is there a quick way of doing this? thanks, joséHow about myArr = myArr.init; Works for both associative and standard arrays
Feb 01 2008