20namespace seqan3::detail
51template <std::ranges::viewable_range resource_t,
52 std::semiregular algorithm_t,
53 std::semiregular algorithm_result_t,
54 typename execution_handler_t = execution_handler_sequential>
55 requires std::ranges::forward_range<resource_t>
56 && std::invocable<algorithm_t,
57 std::ranges::range_reference_t<resource_t>,
59class algorithm_executor_blocking
66 using resource_type = std::views::all_t<resource_t>;
68 using resource_iterator_type = std::ranges::iterator_t<resource_type>;
70 using resource_difference_type = std::iter_difference_t<resource_iterator_type>;
79 using bucket_iterator_type = std::ranges::iterator_t<bucket_type>;
83 using buffer_iterator_type = std::ranges::iterator_t<buffer_type>;
100 algorithm_executor_blocking() =
delete;
102 algorithm_executor_blocking(algorithm_executor_blocking
const &) =
delete;
121 algorithm_executor_blocking(algorithm_executor_blocking && other) noexcept :
122 algorithm_executor_blocking{std::move(other), other.resource_position()}
126 algorithm_executor_blocking & operator=(algorithm_executor_blocking
const &) =
delete;
130 algorithm_executor_blocking & operator=(algorithm_executor_blocking && other)
132 auto old_resource_position = other.resource_position();
134 resource = std::move(other.resource);
135 move_initialise(std::move(other), old_resource_position);
140 ~algorithm_executor_blocking() =
default;
156 algorithm_executor_blocking(resource_t resource,
157 algorithm_t algorithm,
158 algorithm_result_t
const SEQAN3_DOXYGEN_ONLY(result) = algorithm_result_t{},
159 execution_handler_t && exec_handler = execution_handler_t{}) :
160 exec_handler{
std::move(exec_handler)},
162 resource_it{
std::ranges::
begin(this->resource)},
163 algorithm{
std::move(algorithm)}
165 if constexpr (std::same_as<execution_handler_t, execution_handler_parallel>)
166 buffer_size =
static_cast<size_t>(std::ranges::distance(this->resource));
168 buffer.resize(buffer_size);
169 buffer_it = buffer.end();
170 buffer_end_it = buffer_it;
198 while (status == fill_status::empty_buffer);
201 if (status == fill_status::end_of_resource)
204 assert(status == fill_status::non_empty_buffer);
205 assert(bucket_it != buffer_it->end());
207 result = std::ranges::iter_move(bucket_it);
215 return resource_it == std::ranges::end(resource);
224 algorithm_executor_blocking(algorithm_executor_blocking && other,
225 resource_difference_type old_resource_position) noexcept :
226 resource{std::move(other.resource)}
228 move_initialise(std::move(other), old_resource_position);
237 resource_difference_type resource_position()
240 auto position = std::ranges::distance(std::ranges::begin(resource), resource_it);
241 assert(position >= 0);
246 fill_status fill_buffer()
248 if (!is_buffer_empty())
249 return fill_status::non_empty_buffer;
252 return fill_status::end_of_resource;
258 for (buffer_end_it = buffer_it; buffer_end_it != buffer.end() && !
is_eof(); ++buffer_end_it, ++resource_it)
260 exec_handler.execute(algorithm,
262 [target_buffer_it = buffer_end_it](
auto && algorithm_result)
264 target_buffer_it->push_back(std::move(algorithm_result));
271 find_next_non_empty_bucket();
273 if (is_buffer_empty())
274 return fill_status::empty_buffer;
276 return fill_status::non_empty_buffer;
282 bool is_buffer_empty()
const
284 return buffer_it == buffer_end_it;
298 for (
auto & bucket : buffer)
302 buffer_it = buffer.begin();
313 void find_next_non_empty_bucket()
315 assert(buffer_it <= buffer_end_it);
319 [](
auto const & buffer)
321 return !buffer.empty();
324 if (buffer_it != buffer_end_it)
325 bucket_it = buffer_it->begin();
335 void go_to_next_result()
337 if (++bucket_it == buffer_it->end())
340 find_next_non_empty_bucket();
345 void move_initialise(algorithm_executor_blocking && other, resource_difference_type old_resource_position)
noexcept
347 algorithm = std::move(other.algorithm);
348 buffer_size = std::move(other.buffer_size);
349 exec_handler = std::move(other.exec_handler);
351 resource_it = std::ranges::next(std::ranges::begin(resource), old_resource_position);
354 auto buffer_it_position = other.buffer_it - other.buffer.begin();
355 auto buffer_end_it_position = other.buffer_end_it - other.buffer.begin();
358 if (buffer_it_position != buffer_end_it_position)
359 bucket_it_position = other.bucket_it - other.buffer_it->begin();
362 buffer = std::move(other.buffer);
363 buffer_it = buffer.begin() + buffer_it_position;
364 buffer_end_it = buffer.begin() + buffer_end_it_position;
366 if (buffer_it_position != buffer_end_it_position)
367 bucket_it = buffer_it->begin() + bucket_it_position;
371 execution_handler_t exec_handler{};
374 resource_type resource;
376 resource_iterator_type resource_it{};
378 algorithm_t algorithm{};
381 buffer_type buffer{};
383 buffer_iterator_type buffer_it{};
385 buffer_iterator_type buffer_end_it{};
387 bucket_iterator_type bucket_it{};
389 size_t buffer_size{1};
398template <
typename resource_rng_t, std::semiregular algorithm_t, std::semiregular algorithm_result_t>
399algorithm_executor_blocking(resource_rng_t &&, algorithm_t, algorithm_result_t
const &)
400 -> algorithm_executor_blocking<resource_rng_t, algorithm_t, algorithm_result_t, execution_handler_sequential>;
Provides seqan3::detail::execution_handler_parallel.
Provides seqan3::detail::execution_handler_sequential.
constexpr auto is_eof
Checks whether a given letter is equal to the EOF constant defined in <cstdio>.
Definition predicate.hpp:72
SeqAn specific customisations in the standard namespace.