File indexing completed on 2025-01-18 09:29:56
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_COMPUTE_ALGORITHM_IS_PERMUTATION_HPP
0012 #define BOOST_COMPUTE_ALGORITHM_IS_PERMUTATION_HPP
0013
0014 #include <iterator>
0015
0016 #include <boost/static_assert.hpp>
0017
0018 #include <boost/compute/system.hpp>
0019 #include <boost/compute/command_queue.hpp>
0020 #include <boost/compute/container/vector.hpp>
0021 #include <boost/compute/detail/iterator_range_size.hpp>
0022 #include <boost/compute/algorithm/equal.hpp>
0023 #include <boost/compute/algorithm/sort.hpp>
0024 #include <boost/compute/type_traits/is_device_iterator.hpp>
0025
0026 namespace boost {
0027 namespace compute {
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 template<class InputIterator1, class InputIterator2>
0044 inline bool is_permutation(InputIterator1 first1,
0045 InputIterator1 last1,
0046 InputIterator2 first2,
0047 InputIterator2 last2,
0048 command_queue &queue = system::default_queue())
0049 {
0050 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator1>::value);
0051 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator2>::value);
0052 typedef typename std::iterator_traits<InputIterator1>::value_type value_type1;
0053 typedef typename std::iterator_traits<InputIterator2>::value_type value_type2;
0054
0055 size_t count1 = detail::iterator_range_size(first1, last1);
0056 size_t count2 = detail::iterator_range_size(first2, last2);
0057
0058 if(count1 != count2) return false;
0059
0060 vector<value_type1> temp1(first1, last1, queue);
0061 vector<value_type2> temp2(first2, last2, queue);
0062
0063 sort(temp1.begin(), temp1.end(), queue);
0064 sort(temp2.begin(), temp2.end(), queue);
0065
0066 return equal(temp1.begin(), temp1.end(),
0067 temp2.begin(), queue);
0068 }
0069
0070 }
0071 }
0072
0073 #endif