Am I getting this all right?

Jarrett Billingsley kb3ctd2 at yahoo.com
Thu Dec 14 17:30:43 PST 2006


"Bill Baxter" <dnewsgroup at billbaxter.com> wrote in message 
news:elsr1j$lu0$1 at digitaldaemon.com...

> Or just use
> foreach(v; set.keys)
>    writefln(v);

That prints "true true true".  :)

> The only reason not would be because opApply is slower than the builtin 
> foreach on an array.  At least for regular arrays.  Not sure if the same 
> is true for AA's.

I think it'd be slower for AAs too because in the class opApply function you 
have to use foreach on the AA that holds the data.  But really I guess it's 
only one method call, so it probably wouldn't be bad at all.  After all, 
custom implementations of opApply work virtually the same way as the 
built-in ones.

> Also does anyone know if .keys and .values are O(1) operations?  Or do 
> they have to allocate a new array and copy keys/values?  That could be an 
> important thing to know.  Should be part of the spec, I think.

They allocate new arrays.  But when you foreach an AA, it doesn't call them. 




More information about the Digitalmars-d-learn mailing list