]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/compute/algorithm/inplace_merge.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / compute / algorithm / inplace_merge.hpp
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@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_INPLACE_MERGE_HPP
12 #define BOOST_COMPUTE_ALGORITHM_INPLACE_MERGE_HPP
13
14 #include <iterator>
15
16 #include <boost/compute/system.hpp>
17 #include <boost/compute/command_queue.hpp>
18 #include <boost/compute/algorithm/merge.hpp>
19 #include <boost/compute/container/vector.hpp>
20
21 namespace boost {
22 namespace compute {
23
24 /// Merges the sorted values in the range [\p first, \p middle) with
25 /// the sorted values in the range [\p middle, \p last) in-place.
26 ///
27 /// Space complexity: \Omega(n)
28 template<class Iterator>
29 inline void inplace_merge(Iterator first,
30 Iterator middle,
31 Iterator last,
32 command_queue &queue = system::default_queue())
33 {
34 BOOST_ASSERT(first < middle && middle < last);
35
36 typedef typename std::iterator_traits<Iterator>::value_type T;
37
38 const context &context = queue.get_context();
39
40 ptrdiff_t left_size = std::distance(first, middle);
41 ptrdiff_t right_size = std::distance(middle, last);
42
43 vector<T> left(left_size, context);
44 vector<T> right(right_size, context);
45
46 copy(first, middle, left.begin(), queue);
47 copy(middle, last, right.begin(), queue);
48
49 ::boost::compute::merge(
50 left.begin(),
51 left.end(),
52 right.begin(),
53 right.end(),
54 first,
55 queue
56 );
57 }
58
59 } // end compute namespace
60 } // end boost namespace
61
62 #endif // BOOST_COMPUTE_ALGORITHM_INPLACE_MERGE_HPP