Merging one Array with Another

Ilya Yaroshenko via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 1 12:39:51 PDT 2015


fix:

	completeSort(x.assumeSorted, y);
	x = x.chain(y).uniq.array;

or

	completeSort(x.assumeSorted, y.uniq.array);
	x ~= y;


On Friday, 1 May 2015 at 19:34:20 UTC, Ilya Yaroshenko wrote:
> If x is already sorted
>
> x = x.completeSort(y).uniq.array;
>
> On Friday, 1 May 2015 at 19:30:08 UTC, Ilya Yaroshenko wrote:
>> Both variants are wrong because uniq needs sorted ranges.
>>
>> Probably you need something like that:
>>
>> x = x.chain(y).sort.uniq.array;
>>
>> On Friday, 1 May 2015 at 19:08:51 UTC, Per Nordlöw wrote:
>>> What's the fastest Phobos-way of doing either
>>>
>>>   x ~= y; // append
>>>   x = x.uniq; // remove duplicates
>>>
>>> or
>>>
>>>   x = (x ~ y).uniq; // append and remove duplicates in one go
>>>
>>> provided that
>>>
>>>   T[] x, y;
>>>
>>> ?



More information about the Digitalmars-d-learn mailing list