equal_range
#
Overloads#
equal_range(exec, first, last, value)
#
-
template<typename DerivedPolicy, typename ForwardIterator, typename LessThanComparable>
thrust::pair<ForwardIterator, ForwardIterator> thrust::equal_range( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- ForwardIterator first,
- ForwardIterator last,
- const LessThanComparable &value,
equal_range
is a version of binary search: it attempts to find the element value in an ordered range[first, last)
. The value returned byequal_range
is essentially a combination of the values returned bylower_bound
andupper_bound:
it returns apair
of iteratorsi
andj
such thati
is the first position where value could be inserted without violating the ordering andj
is the last position where value could be inserted without violating the ordering. It follows that every element in the range[i, j)
is equivalent to value, and that[i, j)
is the largest subrange of[first, last)
that has this property.This version of
equal_range
returns apair
of iterators[i, j)
, wherei
is the furthermost iterator in[first, last)
such that, for every iteratork
in[first, i)
,*k < value
.j
is the furthermost iterator in[first, last)
such that, for every iteratork
in[first, j)
,value < *k
isfalse
. For every iteratork
in[i, j)
, neithervalue < *k
nor*k < value
istrue
.The algorithm’s execution is parallelized as determined by
exec
.The following code snippet demonstrates how to use
equal_range
to search for values in a ordered range using thethrust::device
execution 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::equal_range(thrust::device, input.begin(), input.end(), 0); // returns [input.begin(), input.begin() + 1) thrust::equal_range(thrust::device, input.begin(), input.end(), 1); // returns [input.begin() + 1, input.begin() + 1) thrust::equal_range(thrust::device, input.begin(), input.end(), 2); // returns [input.begin() + 1, input.begin() + 2) thrust::equal_range(thrust::device, input.begin(), input.end(), 3); // returns [input.begin() + 2, input.begin() + 2) thrust::equal_range(thrust::device, input.begin(), input.end(), 8); // returns [input.begin() + 4, input.end()) thrust::equal_range(thrust::device, input.begin(), input.end(), 9); // returns [input.end(), input.end())
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:
A
pair
of iterators[i, j)
that define the range of equivalent elements.
equal_range(first, last, value)
#
-
template<class ForwardIterator, class LessThanComparable>
thrust::pair<ForwardIterator, ForwardIterator> thrust::equal_range( - ForwardIterator first,
- ForwardIterator last,
- const LessThanComparable &value,
equal_range
is a version of binary search: it attempts to find the element value in an ordered range[first, last)
. The value returned byequal_range
is essentially a combination of the values returned bylower_bound
andupper_bound:
it returns apair
of iteratorsi
andj
such thati
is the first position where value could be inserted without violating the ordering andj
is the last position where value could be inserted without violating the ordering. It follows that every element in the range[i, j)
is equivalent to value, and that[i, j)
is the largest subrange of[first, last)
that has this property.This version of
equal_range
returns apair
of iterators[i, j)
, wherei
is the furthermost iterator in[first, last)
such that, for every iteratork
in[first, i)
,*k < value
.j
is the furthermost iterator in[first, last)
such that, for every iteratork
in[first, j)
,value < *k
isfalse
. For every iteratork
in[i, j)
, neithervalue < *k
nor*k < value
istrue
.The following code snippet demonstrates how to use
equal_range
to 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::equal_range(input.begin(), input.end(), 0); // returns [input.begin(), input.begin() + 1) thrust::equal_range(input.begin(), input.end(), 1); // returns [input.begin() + 1, input.begin() + 1) thrust::equal_range(input.begin(), input.end(), 2); // returns [input.begin() + 1, input.begin() + 2) thrust::equal_range(input.begin(), input.end(), 3); // returns [input.begin() + 2, input.begin() + 2) thrust::equal_range(input.begin(), input.end(), 8); // returns [input.begin() + 4, input.end()) thrust::equal_range(input.begin(), input.end(), 9); // returns [input.end(), input.end())
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:
A
pair
of iterators[i, j)
that define the range of equivalent elements.
equal_range(exec, first, last, value, comp)
#
-
template<typename DerivedPolicy, typename ForwardIterator, typename T, typename StrictWeakOrdering>
thrust::pair<ForwardIterator, ForwardIterator> thrust::equal_range( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- ForwardIterator first,
- ForwardIterator last,
- const T &value,
- StrictWeakOrdering comp,
equal_range
is a version of binary search: it attempts to find the element value in an ordered range[first, last)
. The value returned byequal_range
is essentially a combination of the values returned bylower_bound
andupper_bound:
it returns apair
of iteratorsi
andj
such thati
is the first position where value could be inserted without violating the ordering andj
is the last position where value could be inserted without violating the ordering. It follows that every element in the range[i, j)
is equivalent to value, and that[i, j)
is the largest subrange of[first, last)
that has this property.This version of
equal_range
returns apair
of iterators[i, j)
.i
is the furthermost iterator in[first, last)
such that, for every iteratork
in[first, i)
,comp(*k, value)
istrue
.j
is the furthermost iterator in[first, last)
such that, for every iteratork
in[first, last)
,comp(value, *k)
isfalse
. For every iteratork
in[i, j)
, neithercomp(value, *k)
norcomp(*k, value)
istrue
.The algorithm’s execution is parallelized as determined by
exec
.The following code snippet demonstrates how to use
equal_range
to search for values in a ordered range using thethrust::device
execution 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::equal_range(thrust::device, input.begin(), input.end(), 0, less<int>()); // returns [input.begin(), input.begin() + 1) thrust::equal_range(thrust::device, input.begin(), input.end(), 1, less<int>()); // returns [input.begin() + 1, input.begin() + 1) thrust::equal_range(thrust::device, input.begin(), input.end(), 2, less<int>()); // returns [input.begin() + 1, input.begin() + 2) thrust::equal_range(thrust::device, input.begin(), input.end(), 3, less<int>()); // returns [input.begin() + 2, input.begin() + 2) thrust::equal_range(thrust::device, input.begin(), input.end(), 8, less<int>()); // returns [input.begin() + 4, input.end()) thrust::equal_range(thrust::device, input.begin(), input.end(), 9, less<int>()); // returns [input.end(), input.end())
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's
value_type
.StrictWeakOrdering – is a model of Strict Weak Ordering.
- Returns:
A
pair
of iterators[i, j)
that define the range of equivalent elements.
equal_range(first, last, value, comp)
#
-
template<class ForwardIterator, class T, class StrictWeakOrdering>
thrust::pair<ForwardIterator, ForwardIterator> thrust::equal_range( - ForwardIterator first,
- ForwardIterator last,
- const T &value,
- StrictWeakOrdering comp,
equal_range
is a version of binary search: it attempts to find the element value in an ordered range[first, last)
. The value returned byequal_range
is essentially a combination of the values returned bylower_bound
andupper_bound:
it returns apair
of iteratorsi
andj
such thati
is the first position where value could be inserted without violating the ordering andj
is the last position where value could be inserted without violating the ordering. It follows that every element in the range[i, j)
is equivalent to value, and that[i, j)
is the largest subrange of[first, last)
that has this property.This version of
equal_range
returns apair
of iterators[i, j)
.i
is the furthermost iterator in[first, last)
such that, for every iteratork
in[first, i)
,comp(*k, value)
istrue
.j
is the furthermost iterator in[first, last)
such that, for every iteratork
in[first, last)
,comp(value, *k)
isfalse
. For every iteratork
in[i, j)
, neithercomp(value, *k)
norcomp(*k, value)
istrue
.The following code snippet demonstrates how to use
equal_range
to 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::equal_range(input.begin(), input.end(), 0, less<int>()); // returns [input.begin(), input.begin() + 1) thrust::equal_range(input.begin(), input.end(), 1, less<int>()); // returns [input.begin() + 1, input.begin() + 1) thrust::equal_range(input.begin(), input.end(), 2, less<int>()); // returns [input.begin() * + 1, input.begin() + 2) thrust::equal_range(input.begin(), input.end(), 3, less<int>()); // returns [input.begin() + 2, input.begin() + 2) thrust::equal_range(input.begin(), input.end(), 8, less<int>()); // returns [input.begin() + 4, input.end()) thrust::equal_range(input.begin(), input.end(), 9, less<int>()); // returns [input.end(), input.end())
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's
value_type
.StrictWeakOrdering – is a model of Strict Weak Ordering.
- Returns:
A
pair
of iterators[i, j)
that define the range of equivalent elements.