Concatenate 2 ranges

Vladimir Panteleev via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Nov 11 05:33:20 PST 2016


On Friday, 11 November 2016 at 13:30:17 UTC, RazvanN wrote:
> I know that I can use the .array property, but I think that 
> this iterates through all of my elements. Using 
> assumeSorted(chain(r1, r2).array) will return a SortedRange, 
> but I am not sure what the complexity for this operation is.

.array allocates, so it's going to be O(n), but the allocation 
will probably be more expensive.

> Is there a way to concatenate 2 ranges (SortedRange in my case) 
> in O(1) time?

assumeSorted(chain(a, b)) ?

This works for me:

auto r = assumeSorted(chain([1, 2, 3].sort(), [1, 2, 3].sort()));



More information about the Digitalmars-d-learn mailing list