thrust
Modules | Functions
Searching
Algorithms

Modules

 Binary Search

Functions

template<typename InputIterator , typename T >
InputIterator thrust::find (InputIterator first, InputIterator last, const T &value)
template<typename InputIterator , typename Predicate >
InputIterator thrust::find_if (InputIterator first, InputIterator last, Predicate pred)
template<typename InputIterator , typename Predicate >
InputIterator thrust::find_if_not (InputIterator first, InputIterator last, Predicate pred)
template<typename InputIterator1 , typename InputIterator2 >
thrust::pair< InputIterator1,
InputIterator2 > 
thrust::mismatch (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2)
template<typename InputIterator1 , typename InputIterator2 , typename BinaryPredicate >
thrust::pair< InputIterator1,
InputIterator2 > 
thrust::mismatch (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate pred)
template<typename ForwardIterator , typename Predicate >
ForwardIterator thrust::partition_point (ForwardIterator first, ForwardIterator last, Predicate pred)

Detailed Description

// end reordering


Function Documentation

template<typename InputIterator , typename T >
InputIterator thrust::find ( InputIterator  first,
InputIterator  last,
const T &  value 
)

find returns the first iterator i in the range [first, last) such that *i == value or last if no such iterator exists.

Parameters:
firstBeginning of the sequence to search.
lastEnd of the sequence to search.
valueThe value to find.
Returns:
The first iterator i such that *i == value or last.
Template Parameters:
InputIteratoris a model of Input Iterator and InputIterator's value_type is equality comparable to type T.
Tis a model of EqualityComparable.
  #include <thrust/find.h>
  #include <thrust/device_vector.h>
  ...
  thrust::device_vector<int> input(4);

  input[0] = 0;
  input[1] = 5;
  input[2] = 3;
  input[3] = 7;

  thrust::device_vector<int>::iterator iter;

  iter = thrust::find(input.begin(), input.end(), 3); // returns input.first() + 2
  iter = thrust::find(input.begin(), input.end(), 5); // returns input.first() + 1
  iter = thrust::find(input.begin(), input.end(), 9); // returns input.end()
See also:
find_if
mismatch
template<typename InputIterator , typename Predicate >
InputIterator thrust::find_if ( InputIterator  first,
InputIterator  last,
Predicate  pred 
)

find_if returns the first iterator i in the range [first, last) such that pred(*i) is true or last if no such iterator exists.

Parameters:
firstBeginning of the sequence to search.
lastEnd of the sequence to search.
predA predicate used to test range elements.
Returns:
The first iterator i such that pred(*i) is true, or last.
Template Parameters:
InputIteratoris a model of Input Iterator.
Predicateis a model of Predicate.
  #include <thrust/find.h>
  #include <thrust/device_vector.h>

  struct greater_than_four
  {
      bool operator()(int x)
      {
          return x > 4;
      }
  };

  struct greater_than_ten
  {
      bool operator()(int x)
      {
          return x > 10;
      }
  };

  ...
  thrust::device_vector<int> input(4);

  input[0] = 0;
  input[1] = 5;
  input[2] = 3;
  input[3] = 7;

  thrust::device_vector<int>::iterator iter;

  iter = thrust::find_if(input.begin(), input.end(), greater_than_four()); // returns input.first() + 1

  iter = thrust::find_if(input.begin(), input.end(), greater_than_ten());  // returns input.end()
See also:
find
find_if_not
mismatch
template<typename InputIterator , typename Predicate >
InputIterator thrust::find_if_not ( InputIterator  first,
InputIterator  last,
Predicate  pred 
)

find_if_not returns the first iterator i in the range [first, last) such that pred(*i) is false or last if no such iterator exists.

Parameters:
firstBeginning of the sequence to search.
lastEnd of the sequence to search.
predA predicate used to test range elements.
Returns:
The first iterator i such that pred(*i) is false, or last.
Template Parameters:
InputIteratoris a model of Input Iterator.
Predicateis a model of Predicate.
  #include <thrust/find.h>
  #include <thrust/device_vector.h>

  struct greater_than_four
  {
      bool operator()(int x)
      {
          return x > 4;
      }
  };

  struct greater_than_ten
  {
      bool operator()(int x)
      {
          return x > 10;
      }
  };

  ...
  thrust::device_vector<int> input(4);

  input[0] = 0;
  input[1] = 5;
  input[2] = 3;
  input[3] = 7;

  thrust::device_vector<int>::iterator iter;

  iter = thrust::find_if_not(input.begin(), input.end(), greater_than_four()); // returns input.first()

  iter = thrust::find_if_not(input.begin(), input.end(), greater_than_ten());  // returns input.first()
See also:
find
find_if
mismatch
template<typename InputIterator1 , typename InputIterator2 >
thrust::pair<InputIterator1, InputIterator2> thrust::mismatch ( InputIterator1  first1,
InputIterator1  last1,
InputIterator2  first2 
)

mismatch finds the first position where the two ranges [first1, last1) and [first2, first2 + (last1 - first1)) differ. The two versions of mismatch use different tests for whether elements differ.

This version of mismatch finds the first iterator i in [first1, last1) such that *i == *(first2 + (i - first1)) is false. The return value is a pair whose first element is i and whose second element is *(first2 + (i - first1)). If no such iterator i exists, the return value is a pair whose first element is last1 and whose second element is *(first2 + (last1 - first1)).

Parameters:
first1The beginning of the first sequence.
last1The end of the first sequence.
first2The beginning of the second sequence.
Returns:
The first position where the sequences differ.
Template Parameters:
InputIterator1is a model of Input Iterator and InputIterator1's value_type is equality comparable to InputIterator2's value_type.
InputIterator2is a model of Input Iterator.
  #include <thrust/mismatch.h>
  #include <thrust/device_vector.h>
  ...
  thrust::device_vector<int> vec1(4);
  thrust::device_vector<int> vec2(4);

  vec1[0] = 0;  vec2[0] = 0; 
  vec1[1] = 5;  vec2[1] = 5;
  vec1[2] = 3;  vec2[2] = 8;
  vec1[3] = 7;  vec2[3] = 7;

  typedef thrust::device_vector<int>::iterator Iterator;
  thrust::pair<Iterator,Iterator> result;

  result = thrust::mismatch(vec1.begin(), vec1.end(), vec2.begin());

  // result.first  is vec1.begin() + 2
  // result.second is vec2.begin() + 2
See also:
find
find_if
template<typename InputIterator1 , typename InputIterator2 , typename BinaryPredicate >
thrust::pair<InputIterator1, InputIterator2> thrust::mismatch ( InputIterator1  first1,
InputIterator1  last1,
InputIterator2  first2,
BinaryPredicate  pred 
)

mismatch finds the first position where the two ranges [first1, last1) and [first2, first2 + (last1 - first1)) differ. The two versions of mismatch use different tests for whether elements differ.

This version of mismatch finds the first iterator i in [first1, last1) such that pred(*i, *(first2 + (i - first1)) is false. The return value is a pair whose first element is i and whose second element is *(first2 + (i - first1)). If no such iterator i exists, the return value is a pair whose first element is last1 and whose second element is *(first2 + (last1 - first1)).

Parameters:
first1The beginning of the first sequence.
last1The end of the first sequence.
first2The beginning of the second sequence.
predThe binary predicate to compare elements.
Returns:
The first position where the sequences differ.
Template Parameters:
InputIterator1is a model of Input Iterator.
InputIterator2is a model of Input Iterator.
Predicateis a model of Input Iterator.
  #include <thrust/mismatch.h>
  #include <thrust/device_vector.h>
  ...
  thrust::device_vector<int> vec1(4);
  thrust::device_vector<int> vec2(4);

  vec1[0] = 0;  vec2[0] = 0; 
  vec1[1] = 5;  vec2[1] = 5;
  vec1[2] = 3;  vec2[2] = 8;
  vec1[3] = 7;  vec2[3] = 7;

  typedef thrust::device_vector<int>::iterator Iterator;
  thrust::pair<Iterator,Iterator> result;

  result = thrust::mismatch(vec1.begin(), vec1.end(), vec2.begin(), thrust::equal_to<int>());

  // result.first  is vec1.begin() + 2
  // result.second is vec2.begin() + 2
See also:
find
find_if
template<typename ForwardIterator , typename Predicate >
ForwardIterator thrust::partition_point ( ForwardIterator  first,
ForwardIterator  last,
Predicate  pred 
)

partition_point returns an iterator pointing to the end of the true partition of a partitioned range. partition_point requires the input range [first,last) to be a partition; that is, all elements which satisfy pred shall appear before those that do not.

Parameters:
firstThe beginning of the range to consider.
lastThe end of the range to consider.
predA function object which decides to which partition each element of the range [first, last) belongs.
Returns:
An iterator mid such that all_of(first, mid, pred) and none_of(mid, last, pred) are both true.
Template Parameters:
ForwardIteratoris a model of Forward Iterator, and ForwardIterator's value_type is convertible to Predicate's argument_type.
Predicateis a model of Predicate.
Note:
Though similar, partition_point is not redundant with find_if_not. partition_point's precondition provides an opportunity for a faster implemention.
  #include <thrust/partition.h>

  struct is_even
  {
    __host__ __device__
    bool operator()(const int &x)
    {
      return (x % 2) == 0;
    }
  };
  
  ...

  int A[] = {2, 4, 6, 8, 10, 1, 3, 5, 7, 9};
  int * B = thrust::partition_point(A, A + 10, is_even());
  // B - A is 5
  // [A, B) contains only even values
See also:
partition
find_if_not