]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | //---------------------------------------------------------------------------// |
2 | // Copyright (c) 2014 Roshan <thisisroshansmail@gmail.com> | |
3 | // | |
4 | // Distributed under the Boost Software License, Version 1.0 | |
5 | // See accompanying file LICENSE_1_0.txt or copy at | |
6 | // http://www.boost.org/LICENSE_1_0.txt | |
7 | // | |
8 | // See http://boostorg.github.com/compute for more information. | |
9 | //---------------------------------------------------------------------------// | |
10 | ||
11 | #ifndef BOOST_COMPUTE_ALGORITHM_ROTATE_HPP | |
12 | #define BOOST_COMPUTE_ALGORITHM_ROTATE_HPP | |
13 | ||
14 | #include <boost/compute/system.hpp> | |
15 | #include <boost/compute/algorithm/copy.hpp> | |
16 | #include <boost/compute/container/vector.hpp> | |
17 | ||
18 | namespace boost { | |
19 | namespace compute { | |
20 | ||
21 | /// Performs left rotation such that element at \p n_first comes to the | |
22 | /// beginning. | |
23 | /// | |
b32b8144 FG |
24 | /// Space complexity: \Omega(distance(\p first, \p last)) |
25 | /// | |
7c673cae FG |
26 | /// \see rotate_copy() |
27 | template<class InputIterator> | |
28 | inline void rotate(InputIterator first, | |
29 | InputIterator n_first, | |
30 | InputIterator last, | |
31 | command_queue &queue = system::default_queue()) | |
32 | { | |
33 | //Handle trivial cases | |
34 | if (n_first==first || n_first==last) | |
35 | { | |
36 | return; | |
37 | } | |
38 | ||
39 | //Handle others | |
40 | typedef typename std::iterator_traits<InputIterator>::value_type T; | |
41 | ||
42 | size_t count = detail::iterator_range_size(first, n_first); | |
43 | size_t count2 = detail::iterator_range_size(first, last); | |
44 | ||
45 | const context &context = queue.get_context(); | |
46 | vector<T> temp(count2, context); | |
47 | ::boost::compute::copy(first, last, temp.begin(), queue); | |
48 | ||
49 | ::boost::compute::copy(temp.begin()+count, temp.end(), first, queue); | |
50 | ::boost::compute::copy(temp.begin(), temp.begin()+count, last-count, queue); | |
51 | } | |
52 | ||
53 | } //end compute namespace | |
54 | } //end boost namespace | |
55 | ||
56 | #endif // BOOST_COMPUTE_ALGORITHM_ROTATE_HPP |