Fastest Way to Append Multiple Elements to an Array

Tobias Pankrath via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Dec 26 23:34:42 PST 2014


On Friday, 26 December 2014 at 16:31:48 UTC, Nordlöw wrote:
> On Friday, 26 December 2014 at 16:29:56 UTC, Nordlöw wrote:
>> See my update at
>>
>> https://github.com/nordlow/justd/blob/master/algorithm_ex.d#L1602
>>
>> which tries to merge all the ideas into one adapting algorithm 
>> :)
>>
>> Destroy!
>
> BTW:

writeln(estimateLength([1,2,3],[1,2,3]));

If appending to an int[] this must print 6, if appending to an
int[][] it should
print 2.


> 1. Is is relevant to extend `append` to data being a 
> non-Random-Access range?

Currently it does not work for RA ranges, only for arrays. RA
ranges cannot grow and std.container.Array is no RA range.

> 2. I guess a corresponding `prepend` is motivated aswell, right?

Maybe not, since you cannot efficiently prepend to an array, so
having users call bringToFront explicitly might be more inline
with how e.g. std.container handles complexities.


More information about the Digitalmars-d-learn mailing list