std.algorithm.setops.SetIntersection/setIntersection - multiple declarations
Function setIntersection
Lazily computes the intersection of two or more
input ranges
ranges. The ranges are assumed to be sorted by less. The element
types of the ranges must have a common type.
SetIntersection!(less,Rs) setIntersection(alias less, Rs...)
(
Rs ranges
)
if (Rs .length >= 2 && allSatisfy!(isInputRange, Rs) && !is(CommonType!(staticMap!(ElementType, Rs)) == void));
In the case of multisets, the range with the minimum number of occurences of a given element, propagates the number of occurences of this element to the resulting range.
Parameters
| Name | Description |
|---|---|
| less | Predicate the given ranges are sorted by. |
| ranges | The ranges to compute the intersection for. |
Returns
A range containing the intersection of the given ranges.
Example
import std .algorithm .comparison : equal;
// sets
int[] a = [ 1, 2, 4, 5, 7, 9 ];
int[] b = [ 0, 1, 2, 4, 7, 8 ];
int[] c = [ 0, 1, 4, 5, 7, 8 ];
assert(equal(setIntersection(a, a), a));
assert(equal(setIntersection(a, b), [1, 2, 4, 7]));
assert(equal(setIntersection(a, b, c), [1, 4, 7]));
// multisets
int[] d = [ 1, 1, 2, 2, 7, 7 ];
int[] e = [ 1, 1, 1, 7];
assert(equal(setIntersection(a, d), [1, 2, 7]));
assert(equal(setIntersection(d, e), [1, 1, 7]));
Struct SetIntersection
Lazily computes the intersection of two or more
input ranges
ranges. The ranges are assumed to be sorted by less. The element
types of the ranges must have a common type.
struct SetIntersection(alias less, Rs...)
if (Rs .length >= 2 && allSatisfy!(isInputRange, Rs) && !is(CommonType!(staticMap!(ElementType, Rs)) == void));
In the case of multisets, the range with the minimum number of occurences of a given element, propagates the number of occurences of this element to the resulting range.
Constructors
| Name | Description |
|---|---|
this
(input)
|
Properties
| Name | Type | Description |
|---|---|---|
empty[get]
|
bool | |
front[get]
|
ElementType | |
save[get]
|
SetIntersection |
Methods
| Name | Description |
|---|---|
popFront
()
|
Parameters
| Name | Description |
|---|---|
| less | Predicate the given ranges are sorted by. |
| ranges | The ranges to compute the intersection for. |
Returns
A range containing the intersection of the given ranges.
Example
import std .algorithm .comparison : equal;
// sets
int[] a = [ 1, 2, 4, 5, 7, 9 ];
int[] b = [ 0, 1, 2, 4, 7, 8 ];
int[] c = [ 0, 1, 4, 5, 7, 8 ];
assert(equal(setIntersection(a, a), a));
assert(equal(setIntersection(a, b), [1, 2, 4, 7]));
assert(equal(setIntersection(a, b, c), [1, 4, 7]));
// multisets
int[] d = [ 1, 1, 2, 2, 7, 7 ];
int[] e = [ 1, 1, 1, 7];
assert(equal(setIntersection(a, d), [1, 2, 7]));
assert(equal(setIntersection(d, e), [1, 1, 7]));