Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:56

0001 //---------------------------------------------------------------------------//
0002 // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
0003 //
0004 // Distributed under the Boost Software License, Version 1.0
0005 // See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt
0007 //
0008 // See http://boostorg.github.com/compute for more information.
0009 //---------------------------------------------------------------------------//
0010 
0011 #ifndef BOOST_COMPUTE_ALGORITHM_IS_SORTED_HPP
0012 #define BOOST_COMPUTE_ALGORITHM_IS_SORTED_HPP
0013 
0014 #include <boost/static_assert.hpp>
0015 
0016 #include <boost/compute/command_queue.hpp>
0017 #include <boost/compute/system.hpp>
0018 #include <boost/compute/functional/bind.hpp>
0019 #include <boost/compute/functional/operator.hpp>
0020 #include <boost/compute/algorithm/adjacent_find.hpp>
0021 #include <boost/compute/type_traits/is_device_iterator.hpp>
0022 
0023 namespace boost {
0024 namespace compute {
0025 
0026 /// Returns \c true if the values in the range [\p first, \p last)
0027 /// are in sorted order.
0028 ///
0029 /// \param first first element in the range to check
0030 /// \param last last element in the range to check
0031 /// \param compare comparison function (by default \c less)
0032 /// \param queue command queue to perform the operation
0033 ///
0034 /// \return \c true if the range [\p first, \p last) is sorted
0035 ///
0036 /// Space complexity: \Omega(1)
0037 ///
0038 /// \see sort()
0039 template<class InputIterator, class Compare>
0040 inline bool is_sorted(InputIterator first,
0041                       InputIterator last,
0042                       Compare compare,
0043                       command_queue &queue = system::default_queue())
0044 {
0045     BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
0046     using ::boost::compute::placeholders::_1;
0047     using ::boost::compute::placeholders::_2;
0048 
0049     return ::boost::compute::adjacent_find(
0050         first, last, ::boost::compute::bind(compare, _2, _1), queue
0051     ) == last;
0052 }
0053 
0054 /// \overload
0055 template<class InputIterator>
0056 inline bool is_sorted(InputIterator first,
0057                       InputIterator last,
0058                       command_queue &queue = system::default_queue())
0059 {
0060     BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
0061     typedef typename std::iterator_traits<InputIterator>::value_type value_type;
0062 
0063     return ::boost::compute::is_sorted(
0064         first, last, ::boost::compute::less<value_type>(), queue
0065     );
0066 }
0067 
0068 } // end compute namespace
0069 } // end boost namespace
0070 
0071 #endif // BOOST_COMPUTE_ALGORITHM_IS_SORTED_HPP