mirror of
https://github.com/dlang/phobos.git
synced 2025-05-03 00:20:26 +03:00
Merge pull request #5620 from RazvanN7/Issue_6718
[WIP] Fix Issue 6718 - nWayUnion => nWayMerge, plus true nWayUnion merged-on-behalf-of: Andrei Alexandrescu <andralex@users.noreply.github.com>
This commit is contained in:
commit
bdae5f08f3
1 changed files with 39 additions and 0 deletions
|
@ -864,6 +864,45 @@ MultiwayMerge!(less, RangeOfRanges) multiwayMerge
|
||||||
alias nWayUnion = multiwayMerge;
|
alias nWayUnion = multiwayMerge;
|
||||||
alias NWayUnion = MultiwayMerge;
|
alias NWayUnion = MultiwayMerge;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Computes the union of multiple ranges. The input ranges are passed
|
||||||
|
as a range of ranges and each is assumed to be sorted by $(D
|
||||||
|
less). Computation is done lazily, one union element at a time.
|
||||||
|
`multiwayUnion(ror)` is functionally equivalent to `multiwayMerge(ror).uniq`.
|
||||||
|
|
||||||
|
Params:
|
||||||
|
less = Predicate the given ranges are sorted by.
|
||||||
|
ror = A range of ranges sorted by `less` to compute the intersection for.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
A range of the intersection of the ranges in `ror`.
|
||||||
|
|
||||||
|
See also: $(LREF NWayUnion)
|
||||||
|
*/
|
||||||
|
auto multiwayUnion(alias less = "a < b", RangeOfRanges)(RangeOfRanges ror)
|
||||||
|
{
|
||||||
|
import std.algorithm.iteration : uniq;
|
||||||
|
return ror.multiwayMerge.uniq;
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
@system unittest
|
||||||
|
{
|
||||||
|
import std.algorithm.comparison : equal;
|
||||||
|
|
||||||
|
double[][] a =
|
||||||
|
[
|
||||||
|
[ 1, 4, 7, 8 ],
|
||||||
|
[ 1, 7 ],
|
||||||
|
[ 1, 7, 8],
|
||||||
|
[ 4 ],
|
||||||
|
[ 7 ],
|
||||||
|
];
|
||||||
|
|
||||||
|
auto witness = [1, 4, 7, 8];
|
||||||
|
assert(equal(multiwayUnion(a), witness));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Lazily computes the difference of $(D r1) and $(D r2). The two ranges
|
Lazily computes the difference of $(D r1) and $(D r2). The two ranges
|
||||||
are assumed to be sorted by $(D less). The element types of the two
|
are assumed to be sorted by $(D less). The element types of the two
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue