Merging one Array with Another

Andrea Fontana via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu May 7 01:03:38 PDT 2015


On Thursday, 7 May 2015 at 06:53:39 UTC, Per Nordlöw wrote:
> On Wednesday, 6 May 2015 at 16:05:15 UTC, Andrea Fontana wrote:
>> Maybe a way like this could be useful:
>> http://dpaste.dzfl.pl/7b4b37b490a7
>
> If r is a SortedRange this is very unneccesary wasteful because 
> of the use AA.
>
> In that case you, instead, only want to remove equal 
> consequtive elements without the need for any AA.
>
> I'm guessing there's already an algorithm for this somewhere in 
> Phobos.
>
> Ideas anyone?

It's not that difficult to implement.
You just need to implement a merge() range that returns the min 
of all ranges' front(). Then you can define distinct() for 
SortedRange as:

merge(sortedrange1, sortedrange2, sortedrange3).uniq

Andrea


More information about the Digitalmars-d-learn mailing list