The OpenD Programming Language

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
)
(
scope 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 mir.algorithm.iteration: equal;

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

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

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

Meta