View source code
Display the source code in std/algorithm/setops.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

std.algorithm.setops.SetSymmetricDifference/setSymmetricDifference - multiple declarations

Function setSymmetricDifference

Lazily computes the symmetric difference of r1 and r2, i.e. the elements that are present in exactly one of r1 and r2. The two ranges are assumed to be sorted by less, and the output is also sorted by less. The element types of the two ranges must have a common type.

SetSymmetricDifference!(less,R1,R2) setSymmetricDifference(alias less, R1, R2) (
  R1 r1,
  R2 r2
);

If both ranges are sets (without duplicated elements), the resulting range is going to be a set. If at least one of the ranges is a multiset, the number of occurences of an element x in the resulting range is abs(a-b) where a is the number of occurences of x in r1, b is the number of occurences of x in r2, and abs is the absolute value.

If both arguments are ranges of L-values of the same type then SetSymmetricDifference will also be a range of L-values of that type.

Parameters

NameDescription
less Predicate the given ranges are sorted by.
r1 The first range.
r2 The second range.

Returns

A range of the symmetric difference between r1 and r2.

See also

setDifference

Example

import std.algorithm.comparison : equal;
import std.range.primitives : isForwardRange;

// sets
int[] a = [ 1, 2, 4, 5, 7, 9 ];
int[] b = [ 0, 1, 2, 4, 7, 8 ];
assert(equal(setSymmetricDifference(a, b), [0, 5, 8, 9][]));
static assert(isForwardRange!(typeof(setSymmetricDifference(a, b))));

//mutisets
int[] c = [1, 1, 1, 1, 2, 2, 2, 4, 5, 6];
int[] d = [1, 1, 2, 2, 2, 2, 4, 7, 9];
assert(equal(setSymmetricDifference(c, d), setSymmetricDifference(d, c)));
assert(equal(setSymmetricDifference(c, d), [1, 1, 2, 5, 6, 7, 9]));

Struct SetSymmetricDifference

Lazily computes the symmetric difference of r1 and r2, i.e. the elements that are present in exactly one of r1 and r2. The two ranges are assumed to be sorted by less, and the output is also sorted by less. The element types of the two ranges must have a common type.

struct SetSymmetricDifference(alias less, R1, R2)
  
if (isInputRange!R1 && isInputRange!R2);

If both ranges are sets (without duplicated elements), the resulting range is going to be a set. If at least one of the ranges is a multiset, the number of occurences of an element x in the resulting range is abs(a-b) where a is the number of occurences of x in r1, b is the number of occurences of x in r2, and abs is the absolute value.

If both arguments are ranges of L-values of the same type then SetSymmetricDifference will also be a range of L-values of that type.

Constructors

NameDescription
this (r1, r2)

Properties

NameTypeDescription
empty[get] bool
front[get] auto
save[get] typeof(this)

Methods

NameDescription
opSlice ()
popFront ()

Parameters

NameDescription
less Predicate the given ranges are sorted by.
r1 The first range.
r2 The second range.

Returns

A range of the symmetric difference between r1 and r2.

See also

setDifference

Example

import std.algorithm.comparison : equal;
import std.range.primitives : isForwardRange;

// sets
int[] a = [ 1, 2, 4, 5, 7, 9 ];
int[] b = [ 0, 1, 2, 4, 7, 8 ];
assert(equal(setSymmetricDifference(a, b), [0, 5, 8, 9][]));
static assert(isForwardRange!(typeof(setSymmetricDifference(a, b))));

//mutisets
int[] c = [1, 1, 1, 1, 2, 2, 2, 4, 5, 6];
int[] d = [1, 1, 2, 2, 2, 2, 4, 7, 9];
assert(equal(setSymmetricDifference(c, d), setSymmetricDifference(d, c)));
assert(equal(setSymmetricDifference(c, d), [1, 1, 2, 5, 6, 7, 9]));

Authors

Andrei Alexandrescu

License

Boost License 1.0.