File indexing completed on 2025-01-18 09:29:57
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_COMPUTE_ALGORITHM_SEARCH_HPP
0012 #define BOOST_COMPUTE_ALGORITHM_SEARCH_HPP
0013
0014 #include <boost/static_assert.hpp>
0015
0016 #include <boost/compute/algorithm/detail/search_all.hpp>
0017 #include <boost/compute/algorithm/find.hpp>
0018 #include <boost/compute/container/vector.hpp>
0019 #include <boost/compute/detail/iterator_range_size.hpp>
0020 #include <boost/compute/detail/meta_kernel.hpp>
0021 #include <boost/compute/system.hpp>
0022 #include <boost/compute/type_traits/is_device_iterator.hpp>
0023
0024 namespace boost {
0025 namespace compute {
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041 template<class TextIterator, class PatternIterator>
0042 inline TextIterator search(TextIterator t_first,
0043 TextIterator t_last,
0044 PatternIterator p_first,
0045 PatternIterator p_last,
0046 command_queue &queue = system::default_queue())
0047 {
0048 BOOST_STATIC_ASSERT(is_device_iterator<TextIterator>::value);
0049 BOOST_STATIC_ASSERT(is_device_iterator<PatternIterator>::value);
0050
0051
0052 vector<uint_> matching_indices(
0053 detail::iterator_range_size(t_first, t_last)
0054 - detail::iterator_range_size(p_first, p_last) + 1,
0055 queue.get_context()
0056 );
0057
0058
0059 detail::search_kernel<PatternIterator,
0060 TextIterator,
0061 vector<uint_>::iterator> kernel;
0062
0063 kernel.set_range(p_first, p_last, t_first, t_last, matching_indices.begin());
0064 kernel.exec(queue);
0065
0066 vector<uint_>::iterator index = ::boost::compute::find(
0067 matching_indices.begin(), matching_indices.end(), uint_(1), queue
0068 );
0069
0070
0071 if(index == matching_indices.end())
0072 return t_last;
0073
0074 return t_first + detail::iterator_range_size(matching_indices.begin(), index);
0075 }
0076
0077 }
0078 }
0079
0080 #endif