OSDN Git Service

CUDA
[eos/hostdependX86LINUX64.git] / util / X86LINUX64 / cuda-6.5 / include / thrust / equal.h
1 /*
2  *  Copyright 2008-2013 NVIDIA Corporation
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  */
16
17
18 /*! \file equal.h
19  *  \brief Equality between ranges
20  */
21
22 #pragma once
23
24 #include <thrust/detail/config.h>
25 #include <thrust/detail/execution_policy.h>
26
27 namespace thrust
28 {
29
30
31 /*! \addtogroup reductions
32  *  \{
33  *  \addtogroup comparisons
34  *  \ingroup reductions
35  *  \{
36  */
37
38
39 /*! \p equal returns \c true if the two ranges <tt>[first1, last1)</tt>
40  *  and <tt>[first2, first2 + (last1 - first1))</tt> are identical when
41  *  compared element-by-element, and otherwise returns \c false.
42  *
43  *  This version of \p equal returns \c true if and only if for every
44  *  iterator \c i in <tt>[first1, last1)</tt>, <tt>*i == *(first2 + (i - first1))</tt>.
45  *
46  *  The algorithm's execution is parallelized as determined by \p exec.
47  *
48  *  \param exec The execution policy to use for parallelization.
49  *  \param first1 The beginning of the first sequence.
50  *  \param last1  The end of the first sequence.
51  *  \param first2 The beginning of the second sequence.
52  *  \return \c true, if the sequences are equal; \c false, otherwise.
53  *
54  *  \tparam DerivedPolicy The name of the derived execution policy.
55  *  \tparam InputIterator1 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>,
56  *          and \p InputIterator1's \c value_type is a model of <a href="http://www.sgi.com/tech/stl/EqualityComparable.html">Equality Comparable</a>,
57  *          and \p InputIterator1's \c value_type can be compared for equality with \c InputIterator2's \c value_type.
58  *  \tparam InputIterator2 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>,
59  *          and \p InputIterator2's \c value_type is a model of <a href="http://www.sgi.com/tech/stl/EqualityComparable.html">Equality Comparable</a>,
60  *          and \p InputIterator2's \c value_type can be compared for equality with \c InputIterator1's \c value_type.
61  *
62  *  The following code snippet demonstrates how to use \p equal to test
63  *  two ranges for equality using the \p thrust::host execution policy:
64  *
65  *  \code
66  *  #include <thrust/equal.h>
67  *  #include <thrust/execution_policy.h>
68  *  ...
69  *  int A1[7] = {3, 1, 4, 1, 5, 9, 3};
70  *  int A2[7] = {3, 1, 4, 2, 8, 5, 7};
71  *  ...
72  *  bool result = thrust::equal(thrust::host, A1, A1 + 7, A2);
73  *
74  *  // result == false
75  *  \endcode
76  *
77  *  \see http://www.sgi.com/tech/stl/equal.html
78  */
79 template<typename DerivedPolicy, typename InputIterator1, typename InputIterator2>
80 bool equal(const thrust::detail::execution_policy_base<DerivedPolicy> &exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
81
82
83 /*! \p equal returns \c true if the two ranges <tt>[first1, last1)</tt>
84  *  and <tt>[first2, first2 + (last1 - first1))</tt> are identical when
85  *  compared element-by-element, and otherwise returns \c false.
86  *
87  *  This version of \p equal returns \c true if and only if for every
88  *  iterator \c i in <tt>[first1, last1)</tt>, <tt>*i == *(first2 + (i - first1))</tt>.
89  *
90  *  \param first1 The beginning of the first sequence.
91  *  \param last1  The end of the first sequence.
92  *  \param first2 The beginning of the second sequence.
93  *  \return \c true, if the sequences are equal; \c false, otherwise.
94  *
95  *  \tparam InputIterator1 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>,
96  *          and \p InputIterator1's \c value_type is a model of <a href="http://www.sgi.com/tech/stl/EqualityComparable.html">Equality Comparable</a>,
97  *          and \p InputIterator1's \c value_type can be compared for equality with \c InputIterator2's \c value_type.
98  *  \tparam InputIterator2 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>,
99  *          and \p InputIterator2's \c value_type is a model of <a href="http://www.sgi.com/tech/stl/EqualityComparable.html">Equality Comparable</a>,
100  *          and \p InputIterator2's \c value_type can be compared for equality with \c InputIterator1's \c value_type.
101  *
102  *  The following code snippet demonstrates how to use \p equal to test
103  *  two ranges for equality.
104  *
105  *  \code
106  *  #include <thrust/equal.h>
107  *  ...
108  *  int A1[7] = {3, 1, 4, 1, 5, 9, 3};
109  *  int A2[7] = {3, 1, 4, 2, 8, 5, 7};
110  *  ...
111  *  bool result = thrust::equal(A1, A1 + 7, A2);
112  *
113  *  // result == false
114  *  \endcode
115  *
116  *  \see http://www.sgi.com/tech/stl/equal.html
117  */
118 template <typename InputIterator1, typename InputIterator2>
119 bool equal(InputIterator1 first1, InputIterator1 last1,
120            InputIterator2 first2);
121
122
123 /*! \p equal returns \c true if the two ranges <tt>[first1, last1)</tt>
124  *  and <tt>[first2, first2 + (last1 - first1))</tt> are identical when
125  *  compared element-by-element, and otherwise returns \c false.
126  *
127  *  This version of \p equal returns \c true if and only if for every
128  *  iterator \c i in <tt>[first1, last1)</tt>,
129  *  <tt>binary_pred(*i, *(first2 + (i - first1)))</tt> is \c true.
130  *
131  *  The algorithm's execution is parallelized as determined by \p exec.
132  *
133  *  \param exec The execution policy to use for parallelization.
134  *  \param first1 The beginning of the first sequence.
135  *  \param last1  The end of the first sequence.
136  *  \param first2 The beginning of the second sequence.
137  *  \param binary_pred Binary predicate used to test element equality.
138  *  \return \c true, if the sequences are equal; \c false, otherwise.
139  *
140  *  \tparam DerivedPolicy The name of the derived execution policy.
141  *  \tparam InputIterator1 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>,
142  *          and \p InputIterator1's \c value_type is convertible to \p BinaryPredicate's \c first_argument_type.
143  *  \tparam InputIterator2 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>,
144  *          and \p InputIterator2's \c value_type is convertible to \p BinaryPredicate's \c second_argument_type.
145  *  \tparam BinaryPredicate is a model of <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">Binary Predicate</a>.
146  *
147  *  The following code snippet demonstrates how to use \p equal to compare the
148  *  elements in two ranges modulo 2 using the \p thrust::host execution policy.
149  *
150  *  \code
151  *  #include <thrust/equal.h>
152  *  #include <thrust/execution_policy.h>
153  *  ...
154  *  
155  *  __host__ __device__
156  *  struct compare_modulo_two
157  *  {
158  *    bool operator()(int x, int y)
159  *    {
160  *      return (x % 2) == (y % 2);
161  *    }
162  *  };
163  *  ...
164  *  int x[5] = {0, 2, 4, 6, 8, 10};
165  *  int y[5] = {1, 3, 5, 7, 9, 11};
166  *
167  *  bool result = thrust::equal(x, x + 5, y, compare_modulo_two());
168  *
169  *  // result is true
170  *  \endcode
171  *
172  *  \see http://www.sgi.com/tech/stl/equal.html
173  */
174 template<typename DerivedPolicy, typename InputIterator1, typename InputIterator2, typename BinaryPredicate>
175 bool equal(const thrust::detail::execution_policy_base<DerivedPolicy> &exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate binary_pred);
176
177
178 /*! \p equal returns \c true if the two ranges <tt>[first1, last1)</tt>
179  *  and <tt>[first2, first2 + (last1 - first1))</tt> are identical when
180  *  compared element-by-element, and otherwise returns \c false.
181  *
182  *  This version of \p equal returns \c true if and only if for every
183  *  iterator \c i in <tt>[first1, last1)</tt>,
184  *  <tt>binary_pred(*i, *(first2 + (i - first1)))</tt> is \c true.
185  *
186  *  \param first1 The beginning of the first sequence.
187  *  \param last1  The end of the first sequence.
188  *  \param first2 The beginning of the second sequence.
189  *  \param binary_pred Binary predicate used to test element equality.
190  *  \return \c true, if the sequences are equal; \c false, otherwise.
191  *
192  *  \tparam InputIterator1 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>,
193  *          and \p InputIterator1's \c value_type is convertible to \p BinaryPredicate's \c first_argument_type.
194  *  \tparam InputIterator2 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>,
195  *          and \p InputIterator2's \c value_type is convertible to \p BinaryPredicate's \c second_argument_type.
196  *  \tparam BinaryPredicate is a model of <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">Binary Predicate</a>.
197  *
198  *  The following code snippet demonstrates how to use \p equal to compare the
199  *  elements in two ranges modulo 2.
200  *
201  *  \code
202  *  #include <thrust/equal.h>
203  *  
204  *  __host__ __device__
205  *  struct compare_modulo_two
206  *  {
207  *    bool operator()(int x, int y)
208  *    {
209  *      return (x % 2) == (y % 2);
210  *    }
211  *  };
212  *  ...
213  *  int x[5] = {0, 2, 4, 6, 8, 10};
214  *  int y[5] = {1, 3, 5, 7, 9, 11};
215  *
216  *  bool result = thrust::equal(x, x + 5, y, compare_modulo_two());
217  *
218  *  // result is true
219  *  \endcode
220  *
221  *  \see http://www.sgi.com/tech/stl/equal.html
222  */
223 template <typename InputIterator1, typename InputIterator2, 
224           typename BinaryPredicate>
225 bool equal(InputIterator1 first1, InputIterator1 last1,
226            InputIterator2 first2, BinaryPredicate binary_pred);
227
228
229 /*! \} // end comparisons
230  *  \} // end reductions
231  */
232
233 } // end namespace thrust
234
235 #include <thrust/detail/equal.inl>
236