MCPcopy Create free account
hub / github.com/boostorg/compute / next_permutation

Function next_permutation

include/boost/compute/algorithm/next_permutation.hpp:139–170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

137/// Space complexity: \Omega(1)
138template<class InputIterator>
139inline bool next_permutation(InputIterator first,
140 InputIterator last,
141 command_queue &queue = system::default_queue())
142{
143 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
144 typedef typename std::iterator_traits<InputIterator>::value_type value_type;
145
146 if(first == last) return false;
147
148 InputIterator first_element =
149 detail::next_permutation_helper(first, last, queue);
150
151 if(first_element == last)
152 {
153 reverse(first, last, queue);
154 return false;
155 }
156
157 value_type first_value = first_element.read(queue);
158
159 InputIterator ceiling_element =
160 detail::np_ceiling(first_element + 1, last, first_value, queue);
161
162 value_type ceiling_value = ceiling_element.read(queue);
163
164 first_element.write(ceiling_value, queue);
165 ceiling_element.write(first_value, queue);
166
167 reverse(first_element + 1, last, queue);
168
169 return true;
170}
171
172} // end compute namespace
173} // end boost namespace

Callers 5

BOOST_AUTO_TEST_CASEFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 5

next_permutation_helperFunction · 0.85
reverseFunction · 0.85
np_ceilingFunction · 0.85
readMethod · 0.45
writeMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68