18 #include <type_traits>
54 template <std::ranges::viewable_range resource_t,
55 std::semiregular algorithm_t,
56 std::semiregular algorithm_result_t,
57 typename execution_handler_t = execution_handler_sequential>
59 requires std::ranges::forward_range<resource_t> &&
60 std::invocable<algorithm_t, std::ranges::range_reference_t<resource_t>,
158 algorithm_result_t
const SEQAN3_DOXYGEN_ONLY(result) = algorithm_result_t{},
159 execution_handler_t &&
exec_handler = execution_handler_t{}) :
165 if constexpr (std::same_as<execution_handler_t, execution_handler_parallel>)
194 do { status =
fill_buffer(); }
while (status == fill_status::empty_buffer);
196 if (status == fill_status::end_of_resource)
197 return {std::nullopt};
199 assert(status == fill_status::non_empty_buffer);
218 return fill_status::non_empty_buffer;
221 return fill_status::end_of_resource;
231 target_buffer_it->push_back(
std::move(algorithm_result));
241 return fill_status::empty_buffer;
243 return fill_status::non_empty_buffer;
265 for (
auto & bucket :
buffer)
317 auto old_resource_position = std::ranges::distance(std::ranges::begin(other.resource),
324 auto buffer_it_position = other.buffer_it - other.buffer.begin();
325 auto buffer_end_it_position = other.buffer_end_it - other.buffer.begin();
328 if (buffer_it_position != buffer_end_it_position)
329 bucket_it_position = other.bucket_it - other.buffer_it->begin();
336 if (buffer_it_position != buffer_end_it_position)
368 template <
typename resource_rng_t, std::semiregular algorithm_t, std::semiregular algorithm_result_t>
A blocking algorithm executor for algorithms.
Definition: algorithm_executor_blocking.hpp:64
buffer_type buffer
The buffer storing the algorithm results in buckets.
Definition: algorithm_executor_blocking.hpp:351
void reset_buffer()
Resets the buckets.
Definition: algorithm_executor_blocking.hpp:262
bucket_iterator_type bucket_it
The bucket iterator pointing to the next result within the current bucket.
Definition: algorithm_executor_blocking.hpp:357
fill_status fill_buffer()
Fills the buffer by storing the results of an algorithm invocation into a pre-assigned bucket.
Definition: algorithm_executor_blocking.hpp:215
resource_type resource
The underlying resource.
Definition: algorithm_executor_blocking.hpp:344
algorithm_executor_blocking(resource_rng_t &&, algorithm_t, algorithm_result_t const &) -> algorithm_executor_blocking< resource_rng_t, algorithm_t, algorithm_result_t, execution_handler_sequential >
Deduce the type from the provided arguments and set the sequential execution handler.
std::ranges::iterator_t< resource_type > resource_iterator_type
The iterator over the underlying resource.
Definition: algorithm_executor_blocking.hpp:72
buffer_iterator_type buffer_it
The iterator pointing to the current bucket in the buffer.
Definition: algorithm_executor_blocking.hpp:353
algorithm_executor_blocking()=delete
Deleted default constructor because this class manages an external resource.
std::ranges::iterator_t< buffer_type > buffer_iterator_type
The iterator type of the buffer.
Definition: algorithm_executor_blocking.hpp:85
algorithm_executor_blocking(algorithm_executor_blocking &&other) noexcept
Move constructs the resource of the other executor.
Definition: algorithm_executor_blocking.hpp:123
algorithm_executor_blocking(algorithm_executor_blocking const &)=delete
This class provides unique ownership over the managed resource and is therefor not copyable.
bool is_eof() noexcept
Checks whether the end of the input resource was reached.
Definition: algorithm_executor_blocking.hpp:208
algorithm_executor_blocking(resource_t resource, algorithm_t algorithm, algorithm_result_t const result=algorithm_result_t{}, execution_handler_t &&exec_handler=execution_handler_t{})
Constructs this executor with the given resource range.
Definition: algorithm_executor_blocking.hpp:156
size_t buffer_size
The end get pointer in the buffer.
Definition: algorithm_executor_blocking.hpp:359
~algorithm_executor_blocking()=default
Defaulted.
execution_handler_t exec_handler
The execution policy.
Definition: algorithm_executor_blocking.hpp:341
void find_next_non_empty_bucket()
Finds the first non-empty bucket starting from the current position of the buffer iterator.
Definition: algorithm_executor_blocking.hpp:280
buffer_iterator_type buffer_end_it
The iterator pointing behind the last bucket (must not be the end of the buffer).
Definition: algorithm_executor_blocking.hpp:355
resource_iterator_type resource_it
The iterator over the resource that stores the current state of the executor.
Definition: algorithm_executor_blocking.hpp:346
std::optional< algorithm_result_t > next_result()
}
Definition: algorithm_executor_blocking.hpp:189
algorithm_t algorithm
The algorithm to invoke.
Definition: algorithm_executor_blocking.hpp:348
fill_status
Return status for seqan3::detail::algorithm_executor_blocking::fill_buffer.
Definition: algorithm_executor_blocking.hpp:90
@ end_of_resource
The end of the resource was reached.
Definition: algorithm_executor_blocking.hpp:93
@ empty_buffer
The buffer is empty after calling fill_buffer.
Definition: algorithm_executor_blocking.hpp:92
@ non_empty_buffer
The buffer is not fully consumed yet and contains at least one element.
Definition: algorithm_executor_blocking.hpp:91
std::ranges::iterator_t< bucket_type > bucket_iterator_type
The iterator type of a bucket.
Definition: algorithm_executor_blocking.hpp:81
void go_to_next_result()
Moves the bucket iterator to the next available result.
Definition: algorithm_executor_blocking.hpp:300
std::views::all_t< resource_t > resource_type
The underlying resource type.
Definition: algorithm_executor_blocking.hpp:70
algorithm_executor_blocking & operator=(algorithm_executor_blocking &&other)
Move assigns from the resource of another executor.
Definition: algorithm_executor_blocking.hpp:133
algorithm_executor_blocking & operator=(algorithm_executor_blocking const &)=delete
This class provides unique ownership over the managed resource and is therefor not copyable.
bool is_buffer_empty() const
Whether the internal buffer is empty.
Definition: algorithm_executor_blocking.hpp:249
void move_initialise(algorithm_executor_blocking &&other) noexcept
Helper function to move initialise this from other.
Definition: algorithm_executor_blocking.hpp:311
Provides seqan3::detail::execution_handler_parallel.
Provides seqan3::detail::execution_handler_sequential.
auto const move
A view that turns lvalue-references into rvalue-references.
Definition: move.hpp:70
The internal SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
Adaptations of concepts from the Ranges TS.