my ideas for array operations
Janice Caron
caron800 at googlemail.com
Sun Oct 7 15:36:23 PDT 2007
On 10/7/07, David Brown <dlang at davidb.org> wrote:
> But, I agree, this doesn't need to be in the language, since it is easy to
> write.
It is worth pondering about efficiency though. Most especially when it
comes to concatenation. That is:
string s = cat(a,b,c,d,e,f,g,h);
ought to be more efficient than
string s = a~b~c~d~e~f~g~h;
because the former could, in principle, require only one allocation,
wheras the latter needs seven.
The fast way:
s.length = a.length + b.length + ...
s[0..a.length] = a[];
s[a.length..a.length+b.length] = b[];
...
Order O(N)
The slow way:
s = a ~ b;
s = s ~ c;
...
s = s ~ h;
Order O(N squared)
More information about the Digitalmars-d
mailing list