~ubuntu-branches/ubuntu/utopic/libthrust/utopic

« back to all changes in this revision

Viewing changes to system/detail/generic/sort.inl

  • Committer: Package Import Robot
  • Author(s): Andreas Beckmann
  • Date: 2013-07-10 12:57:33 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20130710125733-my19jic71sqsabaj
Tags: 1.7.0-1
* New upstream release.  (Closes: #715362)
* Update watch file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
{
39
39
 
40
40
 
41
 
template<typename RandomAccessIterator>
42
 
  void sort(tag,
 
41
template<typename ExecutionPolicy,
 
42
         typename RandomAccessIterator>
 
43
  void sort(thrust::execution_policy<ExecutionPolicy> &exec,
43
44
            RandomAccessIterator first,
44
45
            RandomAccessIterator last)
45
46
{
46
47
  typedef typename thrust::iterator_value<RandomAccessIterator>::type value_type; 
47
 
  thrust::sort(first, last, thrust::less<value_type>());
 
48
  thrust::sort(exec, first, last, thrust::less<value_type>());
48
49
} // end sort()
49
50
 
50
51
 
51
 
template<typename RandomAccessIterator,
 
52
template<typename ExecutionPolicy,
 
53
         typename RandomAccessIterator,
52
54
         typename StrictWeakOrdering>
53
 
  void sort(tag,
 
55
  void sort(thrust::execution_policy<ExecutionPolicy> &exec,
54
56
            RandomAccessIterator first,
55
57
            RandomAccessIterator last,
56
58
            StrictWeakOrdering comp)
57
59
{
58
60
  // implement with stable_sort
59
 
  thrust::stable_sort(first,last,comp);
 
61
  thrust::stable_sort(exec, first, last, comp);
60
62
} // end sort()
61
63
 
62
64
 
63
 
template<typename RandomAccessIterator1,
 
65
template<typename ExecutionPolicy,
 
66
         typename RandomAccessIterator1,
64
67
         typename RandomAccessIterator2>
65
 
  void sort_by_key(tag,
 
68
  void sort_by_key(thrust::execution_policy<ExecutionPolicy> &exec,
66
69
                   RandomAccessIterator1 keys_first,
67
70
                   RandomAccessIterator1 keys_last,
68
71
                   RandomAccessIterator2 values_first)
69
72
{
70
73
  typedef typename thrust::iterator_value<RandomAccessIterator1>::type value_type;
71
 
  thrust::sort_by_key(keys_first, keys_last, values_first, thrust::less<value_type>());
 
74
  thrust::sort_by_key(exec, keys_first, keys_last, values_first, thrust::less<value_type>());
72
75
} // end sort_by_key()
73
76
 
74
77
 
75
 
template<typename RandomAccessIterator1,
 
78
template<typename ExecutionPolicy,
 
79
         typename RandomAccessIterator1,
76
80
         typename RandomAccessIterator2,
77
81
         typename StrictWeakOrdering>
78
 
  void sort_by_key(tag,
 
82
  void sort_by_key(thrust::execution_policy<ExecutionPolicy> &exec,
79
83
                   RandomAccessIterator1 keys_first,
80
84
                   RandomAccessIterator1 keys_last,
81
85
                   RandomAccessIterator2 values_first,
82
86
                   StrictWeakOrdering comp)
83
87
{
84
88
  // implement with stable_sort_by_key
85
 
  thrust::stable_sort_by_key(keys_first, keys_last, values_first, comp);
 
89
  thrust::stable_sort_by_key(exec, keys_first, keys_last, values_first, comp);
86
90
} // end sort_by_key()
87
91
 
88
92
 
89
 
template<typename RandomAccessIterator>
90
 
  void stable_sort(tag,
 
93
template<typename ExecutionPolicy,
 
94
         typename RandomAccessIterator>
 
95
  void stable_sort(thrust::execution_policy<ExecutionPolicy> &exec,
91
96
                   RandomAccessIterator first,
92
97
                   RandomAccessIterator last)
93
98
{
94
99
  typedef typename thrust::iterator_value<RandomAccessIterator>::type value_type;
95
 
  thrust::stable_sort(first, last, thrust::less<value_type>());
 
100
  thrust::stable_sort(exec, first, last, thrust::less<value_type>());
96
101
} // end stable_sort()
97
102
 
98
103
 
99
 
template<typename RandomAccessIterator1,
 
104
template<typename ExecutionPolicy,
 
105
         typename RandomAccessIterator1,
100
106
         typename RandomAccessIterator2>
101
 
  void stable_sort_by_key(tag,
 
107
  void stable_sort_by_key(thrust::execution_policy<ExecutionPolicy> &exec,
102
108
                          RandomAccessIterator1 keys_first,
103
109
                          RandomAccessIterator1 keys_last,
104
110
                          RandomAccessIterator2 values_first)
105
111
{
106
112
  typedef typename iterator_value<RandomAccessIterator1>::type value_type;
107
 
  thrust::stable_sort_by_key(keys_first, keys_last, values_first, thrust::less<value_type>());
 
113
  thrust::stable_sort_by_key(exec, keys_first, keys_last, values_first, thrust::less<value_type>());
108
114
} // end stable_sort_by_key()
109
115
 
110
116
 
111
 
template<typename ForwardIterator>
112
 
  bool is_sorted(tag,
 
117
template<typename ExecutionPolicy, typename ForwardIterator>
 
118
  bool is_sorted(thrust::execution_policy<ExecutionPolicy> &exec,
113
119
                 ForwardIterator first,
114
120
                 ForwardIterator last)
115
121
{
116
 
  return thrust::is_sorted_until(first, last) == last;
 
122
  return thrust::is_sorted_until(exec, first, last) == last;
117
123
} // end is_sorted()
118
124
 
119
125
 
120
 
template<typename ForwardIterator,
 
126
template<typename ExecutionPolicy,
 
127
         typename ForwardIterator,
121
128
         typename Compare>
122
 
  bool is_sorted(tag,
 
129
  bool is_sorted(thrust::execution_policy<ExecutionPolicy> &exec,
123
130
                 ForwardIterator first,
124
131
                 ForwardIterator last,
125
132
                 Compare comp)
126
133
{
127
 
  return thrust::is_sorted_until(first, last, comp) == last;
 
134
  return thrust::is_sorted_until(exec, first, last, comp) == last;
128
135
} // end is_sorted()
129
136
 
130
137
 
131
 
template<typename ForwardIterator>
132
 
  ForwardIterator is_sorted_until(tag,
 
138
template<typename ExecutionPolicy, typename ForwardIterator>
 
139
  ForwardIterator is_sorted_until(thrust::execution_policy<ExecutionPolicy> &exec,
133
140
                                  ForwardIterator first,
134
141
                                  ForwardIterator last)
135
142
{
136
143
  typedef typename thrust::iterator_value<ForwardIterator>::type InputType;
137
144
 
138
 
  return thrust::is_sorted_until(first, last, thrust::less<InputType>());
 
145
  return thrust::is_sorted_until(exec, first, last, thrust::less<InputType>());
139
146
} // end is_sorted_until()
140
147
 
141
148
 
142
 
template<typename ForwardIterator,
 
149
template<typename ExecutionPolicy,
 
150
         typename ForwardIterator,
143
151
         typename Compare>
144
 
  ForwardIterator is_sorted_until(tag,
 
152
  ForwardIterator is_sorted_until(thrust::execution_policy<ExecutionPolicy> &exec,
145
153
                                  ForwardIterator first,
146
154
                                  ForwardIterator last,
147
155
                                  Compare comp)
157
165
  ZipIterator zipped_first = thrust::make_zip_iterator(thrust::make_tuple(first_plus_one, first));
158
166
  ZipIterator zipped_last  = thrust::make_zip_iterator(thrust::make_tuple(last, first));
159
167
 
160
 
  return thrust::get<0>(thrust::find_if(zipped_first, zipped_last, thrust::detail::tuple_binary_predicate<Compare>(comp)).get_iterator_tuple());
 
168
  return thrust::get<0>(thrust::find_if(exec, zipped_first, zipped_last, thrust::detail::tuple_binary_predicate<Compare>(comp)).get_iterator_tuple());
161
169
} // end is_sorted_until()
162
170
 
163
171