stable_sort_by_key
#
Overloads#
stable_sort_by_key(exec, keys_first, keys_last, values_first)
#
-
template<typename DerivedPolicy, typename RandomAccessIterator1, typename RandomAccessIterator2>
void thrust::stable_sort_by_key( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- RandomAccessIterator1 keys_first,
- RandomAccessIterator1 keys_last,
- RandomAccessIterator2 values_first,
stable_sort_by_key
performs a key-value sort. That is,stable_sort_by_key
sorts the elements in[keys_first, keys_last)
and[values_first, values_first + (keys_last - keys_first))
into ascending key order, meaning that ifi
andj
are any two valid iterators in[keys_first, keys_last)
such thati
precedesj
, andp
andq
are iterators in[values_first, values_first + (keys_last - keys_first))
corresponding toi
andj
respectively, then*j
is not less than*i
.As the name suggests,
stable_sort_by_key
is stable: it preserves the relative ordering of equivalent elements. That is, ifx
andy
are elements in[keys_first, keys_last)
such thatx
precedesy
, and if the two elements are equivalent (neitherx < y
nory < x
) then a postcondition ofstable_sort_by_key
is thatx
still precedesy
.This version of
stable_sort_by_key
compares key objects usingoperator<
.The algorithm’s execution is parallelized as determined by
exec
.The following code snippet demonstrates how to use
stable_sort_by_key
to sort an array of characters using integers as sorting keys using thethrust::host
execution policy for parallelization:#include <thrust/sort.h> #include <thrust/execution_policy.h> ... const int N = 6; int keys[N] = { 1, 4, 2, 8, 5, 7}; char values[N] = {'a', 'b', 'c', 'd', 'e', 'f'}; thrust::stable_sort_by_key(thrust::host, keys, keys + N, values); // keys is now { 1, 2, 4, 5, 7, 8} // values is now {'a', 'c', 'b', 'e', 'f', 'd'}
See also
See also
- Parameters:
exec – The execution policy to use for parallelization.
keys_first – The beginning of the key sequence.
keys_last – The end of the key sequence.
values_first – The beginning of the value sequence.
- Template Parameters:
DerivedPolicy – The name of the derived execution policy.
RandomAccessIterator1 – is a model of Random Access Iterator,
RandomAccessIterator1
is mutable, andRandomAccessIterator1's
value_type
is a model of LessThan Comparable, and the ordering relation onRandomAccessIterator1's
value_type
is a strict weak ordering, as defined in the LessThan Comparable requirements.RandomAccessIterator2 – is a model of Random Access Iterator, and
RandomAccessIterator2
is mutable.
- Pre:
The range
[keys_first, keys_last))
shall not overlap the range[values_first, values_first + (keys_last - keys_first))
.
stable_sort_by_key(keys_first, keys_last, values_first)
#
-
template<typename RandomAccessIterator1, typename RandomAccessIterator2>
void thrust::stable_sort_by_key( - RandomAccessIterator1 keys_first,
- RandomAccessIterator1 keys_last,
- RandomAccessIterator2 values_first,
stable_sort_by_key
performs a key-value sort. That is,stable_sort_by_key
sorts the elements in[keys_first, keys_last)
and[values_first, values_first + (keys_last - keys_first))
into ascending key order, meaning that ifi
andj
are any two valid iterators in[keys_first, keys_last)
such thati
precedesj
, andp
andq
are iterators in[values_first, values_first + (keys_last - keys_first))
corresponding toi
andj
respectively, then*j
is not less than*i
.As the name suggests,
stable_sort_by_key
is stable: it preserves the relative ordering of equivalent elements. That is, ifx
andy
are elements in[keys_first, keys_last)
such thatx
precedesy
, and if the two elements are equivalent (neitherx < y
nory < x
) then a postcondition ofstable_sort_by_key
is thatx
still precedesy
.This version of
stable_sort_by_key
compares key objects usingoperator<
.The following code snippet demonstrates how to use
stable_sort_by_key
to sort an array of characters using integers as sorting keys.#include <thrust/sort.h> ... const int N = 6; int keys[N] = { 1, 4, 2, 8, 5, 7}; char values[N] = {'a', 'b', 'c', 'd', 'e', 'f'}; thrust::stable_sort_by_key(keys, keys + N, values); // keys is now { 1, 2, 4, 5, 7, 8} // values is now {'a', 'c', 'b', 'e', 'f', 'd'}
See also
See also
- Parameters:
keys_first – The beginning of the key sequence.
keys_last – The end of the key sequence.
values_first – The beginning of the value sequence.
- Template Parameters:
RandomAccessIterator1 – is a model of Random Access Iterator,
RandomAccessIterator1
is mutable, andRandomAccessIterator1's
value_type
is a model of LessThan Comparable, and the ordering relation onRandomAccessIterator1's
value_type
is a strict weak ordering, as defined in the LessThan Comparable requirements.RandomAccessIterator2 – is a model of Random Access Iterator, and
RandomAccessIterator2
is mutable.
- Pre:
The range
[keys_first, keys_last))
shall not overlap the range[values_first, values_first + (keys_last - keys_first))
.
stable_sort_by_key(exec, keys_first, keys_last, values_first, comp)
#
-
template<typename DerivedPolicy, typename RandomAccessIterator1, typename RandomAccessIterator2, typename StrictWeakOrdering>
void thrust::stable_sort_by_key( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- RandomAccessIterator1 keys_first,
- RandomAccessIterator1 keys_last,
- RandomAccessIterator2 values_first,
- StrictWeakOrdering comp,
stable_sort_by_key
performs a key-value sort. That is,stable_sort_by_key
sorts the elements in[keys_first, keys_last)
and[values_first, values_first + (keys_last - keys_first))
into ascending key order, meaning that ifi
andj
are any two valid iterators in[keys_first, keys_last)
such thati
precedesj
, andp
andq
are iterators in[values_first, values_first + (keys_last - keys_first))
corresponding toi
andj
respectively, then*j
is not less than*i
.As the name suggests,
stable_sort_by_key
is stable: it preserves the relative ordering of equivalent elements. That is, ifx
andy
are elements in[keys_first, keys_last)
such thatx
precedesy
, and if the two elements are equivalent (neitherx < y
nory < x
) then a postcondition ofstable_sort_by_key
is thatx
still precedesy
.This version of
stable_sort_by_key
compares key objects using the function objectcomp
.The algorithm’s execution is parallelized as determined by
exec
.The following code snippet demonstrates how to use
sort_by_key
to sort an array of character values using integers as sorting keys using thethrust::host
execution policy for parallelization. The keys are sorted in descending order using thegreater<int>
comparison operator.#include <thrust/sort.h> #include <thrust/execution_policy.h> ... const int N = 6; int keys[N] = { 1, 4, 2, 8, 5, 7}; char values[N] = {'a', 'b', 'c', 'd', 'e', 'f'}; thrust::stable_sort_by_key(thrust::host, keys, keys + N, values, ::cuda::std::greater<int>()); // keys is now { 8, 7, 5, 4, 2, 1} // values is now {'d', 'f', 'e', 'b', 'c', 'a'}
See also
See also
- Parameters:
exec – The execution policy to use for parallelization.
keys_first – The beginning of the key sequence.
keys_last – The end of the key sequence.
values_first – The beginning of the value sequence.
comp – Comparison operator.
- Template Parameters:
DerivedPolicy – The name of the derived execution policy.
RandomAccessIterator1 – is a model of Random Access Iterator,
RandomAccessIterator1
is mutable, andRandomAccessIterator1's
value_type
is convertible toStrictWeakOrdering's
first argument type and second argument type.RandomAccessIterator2 – is a model of Random Access Iterator, and
RandomAccessIterator2
is mutable.StrictWeakOrdering – is a model of Strict Weak Ordering.
- Pre:
The range
[keys_first, keys_last))
shall not overlap the range[values_first, values_first + (keys_last - keys_first))
.
stable_sort_by_key(keys_first, keys_last, values_first, comp)
#
-
template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename StrictWeakOrdering>
void thrust::stable_sort_by_key( - RandomAccessIterator1 keys_first,
- RandomAccessIterator1 keys_last,
- RandomAccessIterator2 values_first,
- StrictWeakOrdering comp,
stable_sort_by_key
performs a key-value sort. That is,stable_sort_by_key
sorts the elements in[keys_first, keys_last)
and[values_first, values_first + (keys_last - keys_first))
into ascending key order, meaning that ifi
andj
are any two valid iterators in[keys_first, keys_last)
such thati
precedesj
, andp
andq
are iterators in[values_first, values_first + (keys_last - keys_first))
corresponding toi
andj
respectively, then*j
is not less than*i
.As the name suggests,
stable_sort_by_key
is stable: it preserves the relative ordering of equivalent elements. That is, ifx
andy
are elements in[keys_first, keys_last)
such thatx
precedesy
, and if the two elements are equivalent (neitherx < y
nory < x
) then a postcondition ofstable_sort_by_key
is thatx
still precedesy
.This version of
stable_sort_by_key
compares key objects using the function objectcomp
.The following code snippet demonstrates how to use
sort_by_key
to sort an array of character values using integers as sorting keys. The keys are sorted in descending order using the greater<int> comparison operator.#include <thrust/sort.h> ... const int N = 6; int keys[N] = { 1, 4, 2, 8, 5, 7}; char values[N] = {'a', 'b', 'c', 'd', 'e', 'f'}; thrust::stable_sort_by_key(keys, keys + N, values, ::cuda::std::greater<int>()); // keys is now { 8, 7, 5, 4, 2, 1} // values is now {'d', 'f', 'e', 'b', 'c', 'a'}
See also
See also
- Parameters:
keys_first – The beginning of the key sequence.
keys_last – The end of the key sequence.
values_first – The beginning of the value sequence.
comp – Comparison operator.
- Template Parameters:
RandomAccessIterator1 – is a model of Random Access Iterator,
RandomAccessIterator1
is mutable, andRandomAccessIterator1's
value_type
is convertible toStrictWeakOrdering's
first argument type and second argument type.RandomAccessIterator2 – is a model of Random Access Iterator, and
RandomAccessIterator2
is mutable.StrictWeakOrdering – is a model of Strict Weak Ordering.
- Pre:
The range
[keys_first, keys_last))
shall not overlap the range[values_first, values_first + (keys_last - keys_first))
.