| 97 | /// |
| 98 | template<class TextIterator, class PatternIterator> |
| 99 | inline TextIterator find_end(TextIterator t_first, |
| 100 | TextIterator t_last, |
| 101 | PatternIterator p_first, |
| 102 | PatternIterator p_last, |
| 103 | command_queue &queue = system::default_queue()) |
| 104 | { |
| 105 | BOOST_STATIC_ASSERT(is_device_iterator<TextIterator>::value); |
| 106 | BOOST_STATIC_ASSERT(is_device_iterator<PatternIterator>::value); |
| 107 | |
| 108 | const context &context = queue.get_context(); |
| 109 | |
| 110 | // there is no need to check if pattern starts at last n - 1 indices |
| 111 | vector<uint_> matching_indices( |
| 112 | detail::iterator_range_size(t_first, t_last) |
| 113 | + 1 - detail::iterator_range_size(p_first, p_last), |
| 114 | context |
| 115 | ); |
| 116 | |
| 117 | detail::search_kernel<PatternIterator, |
| 118 | TextIterator, |
| 119 | vector<uint_>::iterator> kernel; |
| 120 | |
| 121 | kernel.set_range(p_first, p_last, t_first, t_last, matching_indices.begin()); |
| 122 | kernel.exec(queue); |
| 123 | |
| 124 | using boost::compute::_1; |
| 125 | |
| 126 | vector<uint_>::iterator index = |
| 127 | detail::find_end_helper( |
| 128 | matching_indices.begin(), |
| 129 | matching_indices.end(), |
| 130 | _1 == 1, |
| 131 | queue |
| 132 | ); |
| 133 | |
| 134 | // pattern was not found |
| 135 | if(index == matching_indices.end()) |
| 136 | return t_last; |
| 137 | |
| 138 | return t_first + detail::iterator_range_size(matching_indices.begin(), index); |
| 139 | } |
| 140 | |
| 141 | } //end compute namespace |
| 142 | } //end boost namespace |