thrust

◆ set_symmetric_difference() [2/4]

template<typename InputIterator1 , typename InputIterator2 , typename OutputIterator >
OutputIterator thrust::set_symmetric_difference ( InputIterator1  first1,
InputIterator1  last1,
InputIterator2  first2,
InputIterator2  last2,
OutputIterator  result 
)

set_symmetric_difference constructs a sorted range that is the set symmetric difference of the sorted ranges [first1, last1) and [first2, last2). The return value is the end of the output range.

In the simplest case, set_symmetric_difference performs a set theoretic calculation: it constructs the union of the two sets A - B and B - A, where A and B are the two input ranges. That is, the output range contains a copy of every element that is contained in [first1, last1) but not [first2, last1), and a copy of every element that is contained in [first2, last2) but not [first1, last1). The general case is more complicated, because the input ranges may contain duplicate elements. The generalization is that if [first1, last1) contains m elements that are equivalent to each other and [first2, last1) contains n elements that are equivalent to them, then |m - n| of those elements shall be copied to the output range: the last m - n elements from [first1, last1) if m > n, and the last n - m of these elements from [first2, last2) if m < n.

This version of set_union compares elements using operator<.

Parameters
first1The beginning of the first input range.
last1The end of the first input range.
first2The beginning of the second input range.
last2The end of the second input range.
resultThe beginning of the output range.
Returns
The end of the output range.
Template Parameters
InputIterator1is a model of Input Iterator, InputIterator1 and InputIterator2 have the same value_type, InputIterator1's value_type is a model of LessThan Comparable, the ordering on InputIterator1's value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, and InputIterator1's value_type is convertable to a type in OutputIterator's set of value_types.
InputIterator2is a model of Input Iterator, InputIterator2 and InputIterator1 have the same value_type, InputIterator2's value_type is a model of LessThan Comparable, the ordering on InputIterator2's value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, and InputIterator2's value_type is convertable to a type in OutputIterator's set of value_types.
OutputIteratoris a model of Output Iterator.
Precondition
The ranges [first1, last1) and [first2, last2) shall be sorted with respect to operator<.
The resulting range shall not overlap with either input range.

The following code snippet demonstrates how to use set_symmetric_difference to compute the symmetric difference of two sets of integers sorted in ascending order.

...
int A1[6] = {0, 1, 2, 2, 4, 6, 7};
int A2[5] = {1, 1, 2, 5, 8};
int result[6];
int *result_end = thrust::set_symmetric_difference(A1, A1 + 6, A2, A2 + 5, result);
// result = {0, 4, 5, 6, 7, 8}
See also
http://www.sgi.com/tech/stl/set_symmetric_difference.html
merge
includes
set_difference
set_union
set_intersection
sort
is_sorted