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.

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.

  1. struct SetIntersection(alias less = "a < b", Rs...)
  2. SetIntersection!(less, Rs) setIntersection(Rs ranges)
    SetIntersection!(less, Rs)
    setIntersection
    (
    alias less = "a < b"
    Rs...
    )
    ()
    if (
    Rs.length >= 2 &&
    &&
    !is(CommonType!(staticMap!(ElementType, Rs)) == void)
    )

Parameters

less

Predicate the given ranges are sorted by.

ranges Rs

The ranges to compute the intersection for.

Return Value

Type: SetIntersection!(less, Rs)

A range containing the intersection of the given ranges.

Examples

1 import std.algorithm.comparison : equal;
2 
3 // sets
4 int[] a = [ 1, 2, 4, 5, 7, 9 ];
5 int[] b = [ 0, 1, 2, 4, 7, 8 ];
6 int[] c = [ 0, 1, 4, 5, 7, 8 ];
7 assert(equal(setIntersection(a, a), a));
8 assert(equal(setIntersection(a, b), [1, 2, 4, 7]));
9 assert(equal(setIntersection(a, b, c), [1, 4, 7]));
10 
11 // multisets
12 int[] d = [ 1, 1, 2, 2, 7, 7 ];
13 int[] e = [ 1, 1, 1, 7];
14 assert(equal(setIntersection(a, d), [1, 2, 7]));
15 assert(equal(setIntersection(d, e), [1, 1, 7]));

Meta

Suggestion Box / Bug Report