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

1 import std.algorithm.comparison : equal;
2 
3 // sets
4 double[][] a =
5 [
6     [ 1, 4, 7, 8 ],
7     [ 1, 7 ],
8     [ 1, 7, 8],
9     [ 4 ],
10     [ 7 ],
11 ];
12 
13 auto witness = [1, 4, 7, 8];
14 assert(equal(multiwayUnion(a), witness));
15 
16 // multisets
17 double[][] b =
18 [
19     [ 1, 1, 1, 4, 7, 8 ],
20     [ 1, 7 ],
21     [ 1, 7, 7, 8],
22     [ 4 ],
23     [ 7 ],
24 ];
25 assert(equal(multiwayUnion(b), witness));
26 
27 double[][] c =
28 [
29     [9, 8, 8, 8, 7, 6],
30     [9, 8, 6],
31     [9, 8, 5]
32 ];
33 auto witness2 = [9, 8, 7, 6, 5];
34 assert(equal(multiwayUnion!"a > b"(c), witness2));

Meta

Suggestion Box / Bug Report