multiwayUnion

Computes the union of multiple ranges. The input ranges are passed as a range of ranges and each is assumed to be sorted by less. Computation is done lazily, one union element at a time. multiwayUnion(ror) is functionally equivalent to multiwayMerge(ror).uniq.

"The output of multiwayUnion has no duplicates even when its inputs contain duplicates."

multiwayUnion
(
alias less = "a < b"
RangeOfRanges
)
(
RangeOfRanges ror
)

Parameters

less

Predicate the given ranges are sorted by.

ror RangeOfRanges

A range of ranges sorted by less to compute the intersection for.

Return Value

Type: auto

A range of the union of the ranges in ror.

See also: multiwayMerge

Examples

import std.algorithm.comparison : equal;

// sets
double[][] a =
[
    [ 1, 4, 7, 8 ],
    [ 1, 7 ],
    [ 1, 7, 8],
    [ 4 ],
    [ 7 ],
];

auto witness = [1, 4, 7, 8];
assert(equal(multiwayUnion(a), witness));

// multisets
double[][] b =
[
    [ 1, 1, 1, 4, 7, 8 ],
    [ 1, 7 ],
    [ 1, 7, 7, 8],
    [ 4 ],
    [ 7 ],
];
assert(equal(multiwayUnion(b), witness));

double[][] c =
[
    [9, 8, 8, 8, 7, 6],
    [9, 8, 6],
    [9, 8, 5]
];
auto witness2 = [9, 8, 7, 6, 5];
assert(equal(multiwayUnion!"a > b"(c), witness2));

Meta