thrust::binary_search#
Overloads#
binary_search(exec, first, last, value)#
-
template<typename DerivedPolicy, typename ForwardIterator, typename LessThanComparable>
bool thrust::binary_search( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- ForwardIterator first,
- ForwardIterator last,
- const LessThanComparable &value,
binary_searchis a version of binary search: it attempts to find the element value in an ordered range[first, last). It returnstrueif an element that is equivalent tovalueis present in[first, last)andfalseif no such element exists. Specifically, this version returnstrueif and only if there exists an iteratoriin[first, last)such that*i < valueandvalue < *iare bothfalse.The algorithm’s execution is parallelized as determined by
exec.The following code snippet demonstrates how to use
binary_searchto search for values in a ordered range using thethrust::deviceexecution policy for parallelization:#include <thrust/binary_search.h> #include <thrust/device_vector.h> #include <thrust/execution_policy.h> ... thrust::device_vector<int> input(5); input[0] = 0; input[1] = 2; input[2] = 5; input[3] = 7; input[4] = 8; thrust::binary_search(thrust::device, input.begin(), input.end(), 0); // returns true thrust::binary_search(thrust::device, input.begin(), input.end(), 1); // returns false thrust::binary_search(thrust::device, input.begin(), input.end(), 2); // returns true thrust::binary_search(thrust::device, input.begin(), input.end(), 3); // returns false thrust::binary_search(thrust::device, input.begin(), input.end(), 8); // returns true thrust::binary_search(thrust::device, input.begin(), input.end(), 9); // returns false
See also
See also
See also
- Parameters:
exec – The execution policy to use for parallelization.
first – The beginning of the ordered sequence.
last – The end of the ordered sequence.
value – The value to be searched.
- Template Parameters:
DerivedPolicy – The name of the derived execution policy.
ForwardIterator – is a model of Forward Iterator.
LessThanComparable – is a model of LessThanComparable.
- Returns:
trueif an equivalent element exists in[first, last), otherwisefalse.
binary_search(first, last, value)#
-
template<class ForwardIterator, class LessThanComparable>
bool thrust::binary_search( - ForwardIterator first,
- ForwardIterator last,
- const LessThanComparable &value,
binary_searchis a version of binary search: it attempts to find the element value in an ordered range[first, last). It returnstrueif an element that is equivalent tovalueis present in[first, last)andfalseif no such element exists. Specifically, this version returnstrueif and only if there exists an iteratoriin[first, last)such that*i < valueandvalue < *iare bothfalse.The following code snippet demonstrates how to use
binary_searchto search for values in a ordered range.#include <thrust/binary_search.h> #include <thrust/device_vector.h> ... thrust::device_vector<int> input(5); input[0] = 0; input[1] = 2; input[2] = 5; input[3] = 7; input[4] = 8; thrust::binary_search(input.begin(), input.end(), 0); // returns true thrust::binary_search(input.begin(), input.end(), 1); // returns false thrust::binary_search(input.begin(), input.end(), 2); // returns true thrust::binary_search(input.begin(), input.end(), 3); // returns false thrust::binary_search(input.begin(), input.end(), 8); // returns true thrust::binary_search(input.begin(), input.end(), 9); // returns false
See also
See also
See also
- Parameters:
first – The beginning of the ordered sequence.
last – The end of the ordered sequence.
value – The value to be searched.
- Template Parameters:
ForwardIterator – is a model of Forward Iterator.
LessThanComparable – is a model of LessThanComparable.
- Returns:
trueif an equivalent element exists in[first, last), otherwisefalse.
binary_search(exec, first, last, value, comp)#
-
template<typename DerivedPolicy, typename ForwardIterator, typename T, typename StrictWeakOrdering>
bool thrust::binary_search( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- ForwardIterator first,
- ForwardIterator last,
- const T &value,
- StrictWeakOrdering comp,
binary_searchis a version of binary search: it attempts to find the element value in an ordered range[first, last). It returnstrueif an element that is equivalent tovalueis present in[first, last)andfalseif no such element exists. Specifically, this version returnstrueif and only if there exists an iteratoriin[first, last)such thatcomp(*i, value)andcomp(value, *i)are bothfalse.The algorithm’s execution is parallelized as determined by
exec.The following code snippet demonstrates how to use
binary_searchto search for values in a ordered range using thethrust::deviceexecution policy for parallelization:#include <thrust/binary_search.h> #include <thrust/device_vector.h> #include <thrust/functional.h> #include <thrust/execution_policy.h> ... thrust::device_vector<int> input(5); input[0] = 0; input[1] = 2; input[2] = 5; input[3] = 7; input[4] = 8; using ::cuda::std::less; thrust::binary_search(thrust::device, input.begin(), input.end(), 0, less<int>()); // returns true thrust::binary_search(thrust::device, input.begin(), input.end(), 1, less<int>()); // returns false thrust::binary_search(thrust::device, input.begin(), input.end(), 2, less<int>()); // returns true thrust::binary_search(thrust::device, input.begin(), input.end(), 3, less<int>()); // returns false thrust::binary_search(thrust::device, input.begin(), input.end(), 8, less<int>()); // returns true thrust::binary_search(thrust::device, input.begin(), input.end(), 9, less<int>()); // returns false
See also
See also
See also
- Parameters:
exec – The execution policy to use for parallelization.
first – The beginning of the ordered sequence.
last – The end of the ordered sequence.
value – The value to be searched.
comp – The comparison operator.
- Template Parameters:
DerivedPolicy – The name of the derived execution policy.
ForwardIterator – is a model of Forward Iterator.
T – is comparable to
ForwardIterator'svalue_type.StrictWeakOrdering – is a model of Strict Weak Ordering.
- Returns:
trueif an equivalent element exists in[first, last), otherwisefalse.
binary_search(first, last, value, comp)#
-
template<class ForwardIterator, class T, class StrictWeakOrdering>
bool thrust::binary_search( - ForwardIterator first,
- ForwardIterator last,
- const T &value,
- StrictWeakOrdering comp,
binary_searchis a version of binary search: it attempts to find the element value in an ordered range[first, last). It returnstrueif an element that is equivalent tovalueis present in[first, last)andfalseif no such element exists. Specifically, this version returnstrueif and only if there exists an iteratoriin[first, last)such thatcomp(*i, value)andcomp(value, *i)are bothfalse.The following code snippet demonstrates how to use
binary_searchto search for values in a ordered range.#include <thrust/binary_search.h> #include <thrust/device_vector.h> #include <thrust/functional.h> ... thrust::device_vector<int> input(5); input[0] = 0; input[1] = 2; input[2] = 5; input[3] = 7; input[4] = 8; using ::cuda::std::less; thrust::binary_search(input.begin(), input.end(), 0, less<int>()); // returns true thrust::binary_search(input.begin(), input.end(), 1, less<int>()); // returns false thrust::binary_search(input.begin(), input.end(), 2, less<int>()); // returns true thrust::binary_search(input.begin(), input.end(), 3, less<int>()); // returns false thrust::binary_search(input.begin(), input.end(), 8, less<int>()); // returns true thrust::binary_search(input.begin(), input.end(), 9, less<int>()); // returns false
See also
See also
See also
- Parameters:
first – The beginning of the ordered sequence.
last – The end of the ordered sequence.
value – The value to be searched.
comp – The comparison operator.
- Template Parameters:
ForwardIterator – is a model of Forward Iterator.
T – is comparable to
ForwardIterator'svalue_type.StrictWeakOrdering – is a model of Strict Weak Ordering.
- Returns:
trueif an equivalent element exists in[first, last), otherwisefalse.
binary_search(exec, first, last, values_first, values_last, result)#
-
template<typename DerivedPolicy, typename ForwardIterator, typename InputIterator, typename OutputIterator>
OutputIterator thrust::binary_search( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- ForwardIterator first,
- ForwardIterator last,
- InputIterator values_first,
- InputIterator values_last,
- OutputIterator result,
binary_searchis a vectorized version of binary search: for each iteratorvin[values_first, values_last)it attempts to find the value*vin an ordered range[first, last). It returnstrueif an element that is equivalent tovalueis present in[first, last)andfalseif no such element exists.The algorithm’s execution is parallelized as determined by
exec.The following code snippet demonstrates how to use
binary_searchto search for multiple values in a ordered range using thethrust::deviceexecution policy for parallelization:#include <thrust/binary_search.h> #include <thrust/device_vector.h> #include <thrust/execution_policy.h> ... thrust::device_vector<int> input(5); input[0] = 0; input[1] = 2; input[2] = 5; input[3] = 7; input[4] = 8; thrust::device_vector<int> values(6); values[0] = 0; values[1] = 1; values[2] = 2; values[3] = 3; values[4] = 8; values[5] = 9; thrust::device_vector<bool> output(6); thrust::binary_search(thrust::device, input.begin(), input.end(), values.begin(), values.end(), output.begin()); // output is now [true, false, true, false, true, false]
See also
See also
See also
- Parameters:
exec – The execution policy to use for parallelization.
first – The beginning of the ordered sequence.
last – The end of the ordered sequence.
values_first – The beginning of the search values sequence.
values_last – The end of the search values sequence.
result – The beginning of the output sequence.
- Template Parameters:
DerivedPolicy – The name of the derived execution policy.
ForwardIterator – is a model of Forward Iterator.
InputIterator – is a model of Input Iterator. and
InputIterator'svalue_typeis LessThanComparable.OutputIterator – is a model of Output Iterator. and bool is convertible to
OutputIterator'svalue_type.
- Pre:
The ranges
[first,last)and[result, result + (last - first))shall not overlap.
binary_search(first, last, values_first, values_last, result)#
-
template<class ForwardIterator, class InputIterator, class OutputIterator>
OutputIterator thrust::binary_search( - ForwardIterator first,
- ForwardIterator last,
- InputIterator values_first,
- InputIterator values_last,
- OutputIterator result,
binary_searchis a vectorized version of binary search: for each iteratorvin[values_first, values_last)it attempts to find the value*vin an ordered range[first, last). It returnstrueif an element that is equivalent tovalueis present in[first, last)andfalseif no such element exists.The following code snippet demonstrates how to use
binary_searchto search for multiple values in a ordered range.#include <thrust/binary_search.h> #include <thrust/device_vector.h> ... thrust::device_vector<int> input(5); input[0] = 0; input[1] = 2; input[2] = 5; input[3] = 7; input[4] = 8; thrust::device_vector<int> values(6); values[0] = 0; values[1] = 1; values[2] = 2; values[3] = 3; values[4] = 8; values[5] = 9; thrust::device_vector<bool> output(6); thrust::binary_search(input.begin(), input.end(), values.begin(), values.end(), output.begin()); // output is now [true, false, true, false, true, false]
See also
See also
See also
- Parameters:
first – The beginning of the ordered sequence.
last – The end of the ordered sequence.
values_first – The beginning of the search values sequence.
values_last – The end of the search values sequence.
result – The beginning of the output sequence.
- Template Parameters:
ForwardIterator – is a model of Forward Iterator.
InputIterator – is a model of Input Iterator. and
InputIterator'svalue_typeis LessThanComparable.OutputIterator – is a model of Output Iterator. and bool is convertible to
OutputIterator'svalue_type.
- Pre:
The ranges
[first,last)and[result, result + (last - first))shall not overlap.
binary_search(exec, first, last, values_first, values_last, result, comp)#
-
template<typename DerivedPolicy, typename ForwardIterator, typename InputIterator, typename OutputIterator, typename StrictWeakOrdering>
OutputIterator thrust::binary_search( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- ForwardIterator first,
- ForwardIterator last,
- InputIterator values_first,
- InputIterator values_last,
- OutputIterator result,
- StrictWeakOrdering comp,
binary_searchis a vectorized version of binary search: for each iteratorvin[values_first, values_last)it attempts to find the value*vin an ordered range[first, last). It returnstrueif an element that is equivalent tovalueis present in[first, last)andfalseif no such element exists. This version ofbinary_searchuses function objectcompfor comparison.The algorithm’s execution is parallelized as determined by
exec.The following code snippet demonstrates how to use
binary_searchto search for multiple values in a ordered range using thethrust::deviceexecution policy for parallelization:#include <thrust/binary_search.h> #include <thrust/device_vector.h> #include <thrust/functional.h> #include <thrust/execution_policy.h> ... thrust::device_vector<int> input(5); input[0] = 0; input[1] = 2; input[2] = 5; input[3] = 7; input[4] = 8; thrust::device_vector<int> values(6); values[0] = 0; values[1] = 1; values[2] = 2; values[3] = 3; values[4] = 8; values[5] = 9; thrust::device_vector<bool> output(6); thrust::binary_search(thrust::device, input.begin(), input.end(), values.begin(), values.end(), output.begin(), ::cuda::std::less<T>()); // output is now [true, false, true, false, true, false]
See also
See also
See also
- Parameters:
exec – The execution policy to use for parallelization.
first – The beginning of the ordered sequence.
last – The end of the ordered sequence.
values_first – The beginning of the search values sequence.
values_last – The end of the search values sequence.
result – The beginning of the output sequence.
comp – The comparison operator.
- Template Parameters:
DerivedPolicy – The name of the derived execution policy.
ForwardIterator – is a model of Forward Iterator.
InputIterator – is a model of Input Iterator. and
InputIterator'svalue_typeis LessThanComparable.OutputIterator – is a model of Output Iterator. and bool is convertible to
OutputIterator'svalue_type.StrictWeakOrdering – is a model of Strict Weak Ordering.
- Pre:
The ranges
[first,last)and[result, result + (last - first))shall not overlap.
binary_search(first, last, values_first, values_last, result, comp)#
-
template<class ForwardIterator, class InputIterator, class OutputIterator, class StrictWeakOrdering>
OutputIterator thrust::binary_search( - ForwardIterator first,
- ForwardIterator last,
- InputIterator values_first,
- InputIterator values_last,
- OutputIterator result,
- StrictWeakOrdering comp,
binary_searchis a vectorized version of binary search: for each iteratorvin[values_first, values_last)it attempts to find the value*vin an ordered range[first, last). It returnstrueif an element that is equivalent tovalueis present in[first, last)andfalseif no such element exists. This version ofbinary_searchuses function objectcompfor comparison.The following code snippet demonstrates how to use
binary_searchto search for multiple values in a ordered range.#include <thrust/binary_search.h> #include <thrust/device_vector.h> #include <thrust/functional.h> ... thrust::device_vector<int> input(5); input[0] = 0; input[1] = 2; input[2] = 5; input[3] = 7; input[4] = 8; thrust::device_vector<int> values(6); values[0] = 0; values[1] = 1; values[2] = 2; values[3] = 3; values[4] = 8; values[5] = 9; thrust::device_vector<bool> output(6); thrust::binary_search(input.begin(), input.end(), values.begin(), values.end(), output.begin(), ::cuda::std::less<T>()); // output is now [true, false, true, false, true, false]
See also
See also
See also
- Parameters:
first – The beginning of the ordered sequence.
last – The end of the ordered sequence.
values_first – The beginning of the search values sequence.
values_last – The end of the search values sequence.
result – The beginning of the output sequence.
comp – The comparison operator.
- Template Parameters:
ForwardIterator – is a model of Forward Iterator.
InputIterator – is a model of Input Iterator. and
InputIterator'svalue_typeis LessThanComparable.OutputIterator – is a model of Output Iterator. and bool is convertible to
OutputIterator'svalue_type.StrictWeakOrdering – is a model of Strict Weak Ordering.
- Pre:
The ranges
[first,last)and[result, result + (last - first))shall not overlap.