Re: Concatenate 2 ranges

2016-11-11 Thread Saurabh Das via Digitalmars-d-learn
On Friday, 11 November 2016 at 13:30:17 UTC, RazvanN wrote: I am trying to concatenate 2 ranges of the same type (SortedRange in my case). I have tried merge, join and chain, but the problem is that the result is not an object of the type of the initial ranges. For example: 1. If I use chain

Re: Concatenate 2 ranges

2016-11-11 Thread Vladimir Panteleev via Digitalmars-d-learn
On Friday, 11 November 2016 at 13:39:32 UTC, RazvanN wrote: It does work, the problem is that [1, 2, 3].sort() is of type SortedRange(int[], "a < b") while r is of type SortedRange(Result, "a < b"). This is a problem if you want to return r in a function which has return type

Re: Concatenate 2 ranges

2016-11-11 Thread RazvanN via Digitalmars-d-learn
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

Re: Concatenate 2 ranges

2016-11-11 Thread Vladimir Panteleev via Digitalmars-d-learn
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()));

Concatenate 2 ranges

2016-11-11 Thread RazvanN via Digitalmars-d-learn
I am trying to concatenate 2 ranges of the same type (SortedRange in my case). I have tried merge, join and chain, but the problem is that the result is not an object of the type of the initial ranges. For example: 1. If I use chain(r1, r2), the result will be an object of type Result which