merge

fnMerge!(less, Rs) merge(alias less = "a < b", Rs...)(Rs rs) if (Rs.length >= 2 && allSatisfy!(isInputRange, Rs) && !is(CommonType!(staticMap!(ElementType, Rs)) == void))

Merge multiple sorted ranges rs with less-than predicate function pred into one single sorted output range containing the sorted union of the elements of inputs.

Duplicates are not eliminated, meaning that the total number of elements in the output is the sum of all elements in the ranges passed to it; the length member is offered if all inputs also have length. The element types of all the inputs must have a common type CommonType.

Parameters

lessPredicate the given ranges are sorted by.
rsThe ranges to compute the union for.

Returns

A range containing the union of the given ranges.

Details:

All of its inputs are assumed to be sorted. This can mean that inputs are instances of SortedRange. Use the result of sort, or assumeSorted to merge ranges known to be sorted (show in the example below). Note that there is currently no way of ensuring that two or more instances of SortedRange are sorted using a specific comparison function pred. Therefore no checking is done here to assure that all inputs rs are instances of

SortedRange.

This algorithm is lazy, doing work progressively as elements are pulled off the result.

Time complexity is proportional to the sum of element counts over all inputs.

If all inputs have the same element type and offer it by ref, output becomes a range with mutable front (and back where appropriate) that reflects in the original inputs.

If any of the inputs rs is infinite so is the result (empty being always false).

See Also

multiwayMerge for an analogous function

that merges a dynamic number of ranges.