◆ exclusive_scan_by_key() [6/8]

template<typename InputIterator1 , typename InputIterator2 , typename OutputIterator , typename T , typename BinaryPredicate >
OutputIterator thrust::exclusive_scan_by_key ( InputIterator1  first1,
InputIterator1  last1,
InputIterator2  first2,
OutputIterator  result,
BinaryPredicate  binary_pred 

exclusive_scan_by_key computes an exclusive key-value or 'segmented' prefix sum operation. The term 'exclusive' means that each result does not include the corresponding input operand in the partial sum. The term 'segmented' means that the partial sums are broken into distinct segments. In other words, within each segment a separate exclusive scan operation is computed. Refer to the code sample below for example usage.

This version of exclusive_scan_by_key uses the value init to initialize the exclusive scan operation.

This version of exclusive_scan_by_key uses the binary predicate binary_pred to compare adjacent keys. Specifically, consecutive iterators i and i+1 in the range [first1, last1) belong to the same segment if binary_pred(*i, *(i+1)) is true, and belong to different segments otherwise.

Results are not deterministic for pseudo-associative operators (e.g., addition of floating-point types). Results for pseudo-associative operators may vary from run to run.

first1The beginning of the key sequence.
last1The end of the key sequence.
first2The beginning of the input value sequence.
resultThe beginning of the output value sequence.
initThe initial of the exclusive sum value.
binary_predThe binary predicate used to determine equality of keys.
The end of the output sequence.
first1 may equal result but the range [first1, last1) and the range [result, result + (last1 - first1)) shall not overlap otherwise.
first2 may equal result but the range [first2, first2 + (last1 - first1) and range [result, result + (last1 - first1)) shall not overlap otherwise.

The following code snippet demonstrates how to use exclusive_scan_by_key

#include <thrust/scan.h>
int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3};
int vals[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
int init = 5;
thrust::exclusive_scan_by_key(key, key + 10, vals, vals, init, binary_pred); // in-place scan
// vals is now {5, 6, 7, 5, 6, 5, 5, 6, 7, 8};
See also