mir.algorithm.setops

This is a submodule of mir.algorithm. It contains nothrow @nogc BetterC alternative to MultiwayMerge from std.algorithm.setops.

Members

Functions

multiwayMerge
MultiwayMerge!(naryFun!less, RangeOfRanges) multiwayMerge(RangeOfRanges ror)

Merges multiple sets. The input sets 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. The complexity of one popFront operation is O(log(ror.length)). However, the length of ror decreases as ranges in it are exhausted, so the complexity of a full pass through MultiwayMerge is dependent on the distribution of the lengths of ranges contained within ror. If all ranges have the same length n (worst case scenario), the complexity of a full pass through MultiwayMerge is O(n * ror.length * log(ror.length)), i.e., log(ror.length) times worse than just spanning all ranges in turn. The output comes sorted (unstably) by less. The length of the resulting range is the sum of all lengths of the ranges passed as input. This means that all elements (duplicates included) are transferred to the resulting range. For backward compatibility, multiwayMerge is available under the name nWayUnion and MultiwayMerge under the name of NWayUnion . Future code should use multiwayMerge and MultiwayMerge as nWayUnion and NWayUnion will be deprecated.

multiwayUnion
auto multiwayUnion(RangeOfRanges ror)

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."

unionLength
size_t unionLength(RangeOfRanges ror)

Computes the length of union of multiple ranges. The input ranges are passed as a range of ranges and each is assumed to be sorted by less.

Structs

MultiwayMerge
struct MultiwayMerge(alias less, RangeOfRanges)

Merges multiple sets. The input sets 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. The complexity of one popFront operation is O(log(ror.length)). However, the length of ror decreases as ranges in it are exhausted, so the complexity of a full pass through MultiwayMerge is dependent on the distribution of the lengths of ranges contained within ror. If all ranges have the same length n (worst case scenario), the complexity of a full pass through MultiwayMerge is O(n * ror.length * log(ror.length)), i.e., log(ror.length) times worse than just spanning all ranges in turn. The output comes sorted (unstably) by less. The length of the resulting range is the sum of all lengths of the ranges passed as input. This means that all elements (duplicates included) are transferred to the resulting range. For backward compatibility, multiwayMerge is available under the name nWayUnion and MultiwayMerge under the name of NWayUnion . Future code should use multiwayMerge and MultiwayMerge as nWayUnion and NWayUnion will be deprecated.

Meta

License

Apache-2.0

Authors

Andrei Alexandrescu (original Phobos code), Ilya Yaroshenko (Mir & BetterC rework, optimization).