Public Member Functions | List of all members
thrust::permutation_iterator< ElementIterator, IndexIterator > Class Template Reference

#include <thrust/iterator/permutation_iterator.h>

Inherits type< ElementIterator, IndexIterator >.

Public Member Functions

__host__ __device__ permutation_iterator ()
__host__ __device__ permutation_iterator (ElementIterator x, IndexIterator y)
template<typename OtherElementIterator , typename OtherIndexIterator >
__host__ __device__ permutation_iterator (permutation_iterator< OtherElementIterator, OtherIndexIterator > const &r, typename detail::enable_if_convertible< OtherElementIterator, ElementIterator >::type *=0, typename detail::enable_if_convertible< OtherIndexIterator, IndexIterator >::type *=0)

Detailed Description

template<typename ElementIterator, typename IndexIterator>
class thrust::permutation_iterator< ElementIterator, IndexIterator >

permutation_iterator is an iterator which represents a pointer into a reordered view of a given range. permutation_iterator is an imprecise name; the reordered view need not be a strict permutation. This iterator is useful for fusing a scatter or gather operation with other algorithms.

This iterator takes two arguments:

Note that permutation_iterator is not limited to strict permutations of the given range V. The distance between begin and end of the reindexing iterators is allowed to be smaller compared to the size of the range V, in which case the permutation_iterator only provides a "permutation" of a subrange of V. The indices neither need to be unique. In this same context, it must be noted that the past-the-end permutation_iterator is completely defined by means of the past-the-end iterator to the indices.

The following code snippet demonstrates how to create a permutation_iterator which represents a reordering of the contents of a device_vector.

thrust::device_vector<float> values(4);
values[0] = 10.0f;
values[1] = 20.0f;
values[2] = 30.0f;
values[3] = 40.0f;
values[4] = 50.0f;
values[5] = 60.0f;
values[6] = 70.0f;
values[7] = 80.0f;
indices[0] = 2;
indices[1] = 6;
indices[2] = 1;
indices[3] = 3;
*iter; // returns 30.0f;
iter[0]; // returns 30.0f;
iter[1]; // returns 70.0f;
iter[2]; // returns 20.0f;
iter[3]; // returns 40.0f;
// iter[4] is an out-of-bounds error
*iter = -1.0f; // sets values[2] to -1.0f;
iter[0] = -1.0f; // sets values[2] to -1.0f;
iter[1] = -1.0f; // sets values[6] to -1.0f;
iter[2] = -1.0f; // sets values[1] to -1.0f;
iter[3] = -1.0f; // sets values[3] to -1.0f;
// values is now {10, -1, -1, -1, 50, 60, -1, 80}
See also

The documentation for this class was generated from the following file: