File indexing completed on 2025-01-18 09:30:00
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_COMPUTE_EXPERIMENTAL_SORT_BY_TRANSFORM_HPP
0012 #define BOOST_COMPUTE_EXPERIMENTAL_SORT_BY_TRANSFORM_HPP
0013
0014 #include <iterator>
0015
0016 #include <boost/compute/algorithm/sort_by_key.hpp>
0017 #include <boost/compute/algorithm/transform.hpp>
0018 #include <boost/compute/container/vector.hpp>
0019 #include <boost/compute/detail/iterator_range_size.hpp>
0020 #include <boost/compute/type_traits/result_of.hpp>
0021
0022 namespace boost {
0023 namespace compute {
0024 namespace experimental {
0025
0026 template<class Iterator, class Transform, class Compare>
0027 inline void sort_by_transform(Iterator first,
0028 Iterator last,
0029 Transform transform,
0030 Compare compare,
0031 command_queue &queue = system::default_queue())
0032 {
0033 typedef typename std::iterator_traits<Iterator>::value_type value_type;
0034 typedef typename boost::compute::result_of<Transform(value_type)>::type key_type;
0035
0036 size_t n = detail::iterator_range_size(first, last);
0037 if(n < 2){
0038 return;
0039 }
0040
0041 const context &context = queue.get_context();
0042
0043 ::boost::compute::vector<key_type> keys(n, context);
0044
0045 ::boost::compute::transform(
0046 first,
0047 last,
0048 keys.begin(),
0049 transform,
0050 queue
0051 );
0052
0053 ::boost::compute::sort_by_key(
0054 keys.begin(),
0055 keys.end(),
0056 first,
0057 compare,
0058 queue
0059 );
0060 }
0061
0062 }
0063 }
0064 }
0065
0066 #endif