2
* Copyright 2008-2011 NVIDIA Corporation
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
18
#include <thrust/iterator/iterator_traits.h>
20
#include <thrust/host_vector.h>
31
template <typename InputIterator1,
32
typename InputIterator2,
33
typename OutputIterator,
34
typename StrictWeakOrdering>
35
OutputIterator merge(InputIterator1 first1,
37
InputIterator2 first2,
39
OutputIterator output,
40
StrictWeakOrdering comp)
42
while(first1 != last1 && first2 != last2)
44
if(!comp(*first2, *first1))
60
while(first1 != last1)
67
while(first2 != last2)
78
template <typename RandomAccessIterator,
79
typename StrictWeakOrdering>
80
void inplace_merge(RandomAccessIterator first,
81
RandomAccessIterator middle,
82
RandomAccessIterator last,
83
StrictWeakOrdering comp)
85
typedef typename thrust::iterator_value<RandomAccessIterator>::type value_type;
87
thrust::host_vector<value_type> a( first, middle);
88
thrust::host_vector<value_type> b(middle, last);
90
thrust::detail::host::detail::merge(a.begin(), a.end(), b.begin(), b.end(), first, comp);
94
template <typename InputIterator1,
95
typename InputIterator2,
96
typename InputIterator3,
97
typename InputIterator4,
98
typename OutputIterator1,
99
typename OutputIterator2,
100
typename StrictWeakOrdering>
101
thrust::pair<OutputIterator1,OutputIterator2>
102
merge_by_key(InputIterator1 first1,
103
InputIterator1 last1,
104
InputIterator2 first2,
105
InputIterator2 last2,
106
InputIterator3 first3,
107
InputIterator4 first4,
108
OutputIterator1 output1,
109
OutputIterator2 output2,
110
StrictWeakOrdering comp)
112
while(first1 != last1 && first2 != last2)
114
if(!comp(*first2, *first1))
116
// *first1 <= *first2
135
while(first1 != last1)
145
while(first2 != last2)
155
return thrust::make_pair(output1, output2);
159
template <typename RandomAccessIterator1,
160
typename RandomAccessIterator2,
161
typename StrictWeakOrdering>
162
void inplace_merge_by_key(RandomAccessIterator1 first1,
163
RandomAccessIterator1 middle1,
164
RandomAccessIterator1 last1,
165
RandomAccessIterator2 first2,
166
StrictWeakOrdering comp)
168
typedef typename thrust::iterator_value<RandomAccessIterator1>::type value_type1;
169
typedef typename thrust::iterator_value<RandomAccessIterator2>::type value_type2;
171
RandomAccessIterator2 middle2 = first2 + (middle1 - first1);
172
RandomAccessIterator2 last2 = first2 + (last1 - first1);
174
thrust::host_vector<value_type1> lhs1( first1, middle1);
175
thrust::host_vector<value_type1> rhs1(middle1, last1);
176
thrust::host_vector<value_type2> lhs2( first2, middle2);
177
thrust::host_vector<value_type2> rhs2(middle2, last2);
179
thrust::detail::host::detail::merge_by_key
180
(lhs1.begin(), lhs1.end(), rhs1.begin(), rhs1.end(),
181
lhs2.begin(), rhs2.begin(),
182
first1, first2, comp);
185
} // end namespace detail
186
} // end namespace host
187
} // end namespace detail
188
} // end namespace thrust