35 #include <cugar/basic/types.h> 62 template <
typename Iterator,
typename Predicate>
66 const Predicate predicate)
73 if (predicate( begin[0] ) == predicate( begin[n-1] ))
74 return predicate( begin[0] ) ? begin + n :
begin;
81 const uint32 count2 = count / 2;
83 Iterator mid = begin + count2;
85 if (predicate( *mid ) ==
false)
86 begin = ++mid, count -= count2 + 1;
98 template <
typename Iterator,
typename Value,
typename index_type>
116 index_type count = n;
120 const index_type count2 = count / 2;
122 Iterator mid = begin + count2;
125 begin = ++mid, count -= count2 + 1;
137 template <
typename Iterator,
typename Value,
typename index_type>
154 index_type count = n;
158 const index_type step = count / 2;
160 Iterator it = begin + step;
178 template <
typename Iterator,
typename Value,
typename index_type>
184 return uint32(
lower_bound( x, begin, n ) - begin );
192 template <
typename Iterator,
typename Value,
typename index_type>
198 return index_type(
upper_bound( x, begin, n ) - begin );
210 typename input_iterator1,
211 typename input_iterator2,
212 typename output_iterator>
213 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
215 input_iterator1 first1,
216 input_iterator1 end1,
217 input_iterator2 first2,
218 input_iterator2 end2,
219 output_iterator output)
221 while (first1 != end1 &&
224 if (*first2 < *first1)
240 while (first1 != end1)
248 while (first2 != end2)
266 typename key_iterator1,
267 typename key_iterator2,
268 typename value_iterator1,
269 typename value_iterator2,
270 typename key_iterator,
271 typename value_iterator>
272 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
274 key_iterator1 first1,
276 key_iterator2 first2,
278 value_iterator1 values1,
279 value_iterator2 values2,
280 key_iterator output_keys,
281 value_iterator output_values)
283 while (first1 != end1 &&
286 if (*first2 < *first1)
288 *output_keys = *first2;
289 *output_values = *values2;
296 *output_keys = *first1;
297 *output_values = *values1;
307 while (first1 != end1)
309 *output_keys = *first1;
310 *output_values = *values1;
318 while (first2 != end2)
320 *output_keys = *first2;
321 *output_values = *values2;
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE index_type upper_bound_index(const Value x, Iterator begin, const index_type n)
Definition: algorithms.h:193
thrust::device_vector< T >::iterator begin(thrust::device_vector< T > &vec)
Definition: thrust_view.h:89
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE void merge_by_key(key_iterator1 first1, key_iterator1 end1, key_iterator2 first2, key_iterator2 end2, value_iterator1 values1, value_iterator2 values2, key_iterator output_keys, value_iterator output_values)
Definition: algorithms.h:273
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Iterator upper_bound(const Value x, Iterator begin, const index_type n)
Definition: algorithms.h:138
Define a vector_view POD type and plain_view() for std::vector.
Definition: diff.h:38
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE index_type lower_bound_index(const Value x, Iterator begin, const index_type n)
Definition: algorithms.h:179
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Iterator lower_bound(const Value x, Iterator begin, const index_type n)
Definition: algorithms.h:99
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE void merge(input_iterator1 first1, input_iterator1 end1, input_iterator2 first2, input_iterator2 end2, output_iterator output)
Definition: algorithms.h:214
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Iterator find_pivot(Iterator begin, const uint32 n, const Predicate predicate)
Definition: algorithms.h:63