1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #ifndef BOOST_COMPUTE_ALGORITHM_SEARCH_HPP
- #define BOOST_COMPUTE_ALGORITHM_SEARCH_HPP
- #include <boost/static_assert.hpp>
- #include <boost/compute/algorithm/detail/search_all.hpp>
- #include <boost/compute/algorithm/find.hpp>
- #include <boost/compute/container/vector.hpp>
- #include <boost/compute/detail/iterator_range_size.hpp>
- #include <boost/compute/detail/meta_kernel.hpp>
- #include <boost/compute/system.hpp>
- #include <boost/compute/type_traits/is_device_iterator.hpp>
- namespace boost {
- namespace compute {
- template<class TextIterator, class PatternIterator>
- inline TextIterator search(TextIterator t_first,
- TextIterator t_last,
- PatternIterator p_first,
- PatternIterator p_last,
- command_queue &queue = system::default_queue())
- {
- BOOST_STATIC_ASSERT(is_device_iterator<TextIterator>::value);
- BOOST_STATIC_ASSERT(is_device_iterator<PatternIterator>::value);
-
- vector<uint_> matching_indices(
- detail::iterator_range_size(t_first, t_last)
- - detail::iterator_range_size(p_first, p_last) + 1,
- queue.get_context()
- );
-
- detail::search_kernel<PatternIterator,
- TextIterator,
- vector<uint_>::iterator> kernel;
- kernel.set_range(p_first, p_last, t_first, t_last, matching_indices.begin());
- kernel.exec(queue);
- vector<uint_>::iterator index = ::boost::compute::find(
- matching_indices.begin(), matching_indices.end(), uint_(1), queue
- );
-
- if(index == matching_indices.end())
- return t_last;
- return t_first + detail::iterator_range_size(matching_indices.begin(), index);
- }
- }
- }
- #endif
|