Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: fix & improve parallel algorithms documentation 4 #5966

Merged
merged 20 commits into from
Aug 7, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions libs/core/algorithms/include/hpx/parallel/algorithms/remove.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,13 @@ namespace hpx {
/// assignments, exactly \a last - \a first applications of
/// the operator==().
///
/// \tparam ExPolicy The type of the execution policy to use (deduced).
/// It describes the manner in which the execution
/// of the algorithm may be parallelized and the manner
/// in which it executes the assignments.
/// \tparam FwdIter The type of the source iterators used (deduced).
/// This iterator type must meet the requirements of an
/// forward iterator.
/// \tparam T The type of the value to remove (deduced).
/// This value type must meet the requirements of
/// \a CopyConstructible.
///
/// \param policy The execution policy to use for the scheduling of
/// the iterations.
/// \param first Refers to the beginning of the sequence of elements
/// the algorithm will be applied to.
/// \param last Refers to the end of the sequence of elements the
Expand All @@ -49,26 +43,33 @@ namespace hpx {
/// The \a remove algorithm returns the iterator to the new end
/// of the range.
///
template <typename FwdIter, typename T>
template <typename FwdIter,
typename T = typename std::iterator_traits<FwdIter>::value_type>
FwdIter remove(FwdIter first, FwdIter last, T const& value);

/////////////////////////////////////////////////////////////////////////////
/// Removes all elements satisfying specific criteria from the range
/// [first, last) and returns a past-the-end iterator for the new
/// end of the range. This version removes all elements that are
/// equal to \a value.
/// equal to \a value. Executed according to the policy.
///
/// \note Complexity: Performs not more than \a last - \a first
/// assignments, exactly \a last - \a first applications of
/// the operator==().
///
/// \tparam ExPolicy The type of the execution policy to use (deduced).
/// It describes the manner in which the execution
/// of the algorithm may be parallelized and the manner
/// in which it executes the assignments.
/// \tparam FwdIter The type of the source iterators used (deduced).
/// This iterator type must meet the requirements of an
/// forward iterator.
/// \tparam T The type of the value to remove (deduced).
/// This value type must meet the requirements of
/// \a CopyConstructible.
///
/// \param policy The execution policy to use for the scheduling of
/// the iterations.
/// \param first Refers to the beginning of the sequence of elements
/// the algorithm will be applied to.
/// \param last Refers to the end of the sequence of elements the
Expand All @@ -92,9 +93,11 @@ namespace hpx {
/// The \a remove algorithm returns the iterator to the new end
/// of the range.
///
template <typename ExPolicy, typename FwdIter, typename T>
typename util::detail::algorithm_result<ExPolicy, FwdIter>::type remove(
ExPolicy&& policy, FwdIter first, FwdIter last, T const& value);
template <typename ExPolicy, typename FwdIter,
typename T = typename std::iterator_traits<FwdIter>::value_type>
typename parallel::util::detail::algorithm_result
<ExPolicy, FwdIter>::type remove(
ExPolicy&& policy, FwdIter first, FwdIter last, T const& value);

/// Removes all elements satisfying specific criteria from the range
/// [first, last) and returns a past-the-end iterator for the new
Expand Down Expand Up @@ -145,7 +148,7 @@ namespace hpx {
/// Removes all elements satisfying specific criteria from the range
/// [first, last) and returns a past-the-end iterator for the new
/// end of the range. This version removes all elements for which predicate
/// \a pred returns true.
/// \a pred returns true. Executed according to the policy.
///
/// \note Complexity: Performs not more than \a last - \a first
/// assignments, exactly \a last - \a first applications of
Expand Down Expand Up @@ -202,8 +205,9 @@ namespace hpx {
/// of the range.
///
template <typename ExPolicy, typename FwdIter, typename Pred>
typename util::detail::algorithm_result<ExPolicy, FwdIter>::type remove_if(
ExPolicy&& policy, FwdIter first, FwdIter last, Pred&& pred);
typename parallel::util::detail::algorithm_result<
ExPolicy, FwdIter>::type remove_if(
ExPolicy&& policy, FwdIter first, FwdIter last, Pred&& pred);

} // namespace hpx

Expand Down
50 changes: 27 additions & 23 deletions libs/core/algorithms/include/hpx/parallel/algorithms/replace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ namespace hpx {
/// The assignments in the parallel \a replace algorithm
/// execute in sequential order in the calling thread.
///
///
/// \returns The \a replace algorithm returns a \a void.
///
template <typename Initer, typename T>
template <typename InIter,
typename T = typename std::iterator_traits<InIter>::value_type>
void replace(
InIter first, InIter last, T const& old_value, T const& new_value);

/// Replaces all elements satisfying specific criteria with \a new_value
/// in the range [first, last).
/// in the range [first, last). Executed according to the policy.
///
/// Effects: Substitutes elements referred by the iterator it in the range
/// [first, last) with new_value, when the following corresponding
Expand All @@ -60,7 +60,7 @@ namespace hpx {
/// \tparam FwdIter The type of the source iterators used (deduced).
/// This iterator type must meet the requirements of a
/// forward iterator.
/// \tparam T The type of the old and new values to replace (deduced).
/// \tparam T The type of the old and new values to replace (deduced).
///
/// \param policy The execution policy to use for the scheduling of
/// the iterations.
Expand All @@ -87,13 +87,14 @@ namespace hpx {
/// \a parallel_task_policy and
/// returns \a void otherwise.
///
template <typename ExPolicy, typename FwdIter, typename T>
template <typename ExPolicy, typename FwdIter,
typename T = typename std::iterator_traits<FwdIter>::value_type>
typename parallel::util::detail::algorithm_result<ExPolicy, void>::type
replace(ExPolicy&& policy, FwdIter first, FwdIter last, T const& old_value,
T const& new_value);

/// Replaces all elements satisfying specific criteria (for which predicate
/// \a f returns true) with \a new_value in the range [first, last).
/// \a pred returns true) with \a new_value in the range [first, last).
///
/// Effects: Substitutes elements referred by the iterator it in the range
/// [first, last) with new_value, when the following corresponding
Expand Down Expand Up @@ -136,14 +137,15 @@ namespace hpx {
/// The assignments in the parallel \a replace_if algorithm
/// execute in sequential order in the calling thread.
///
///
/// \returns The \a replace_if algorithm returns \a void.
///
template <typename Iter, typename Pred, typename T>
template <typename Iter, typename Pred,
typename T = typename std::iterator_traits<Iter>::value_type>
void replace_if(Iter first, Iter last, Pred&& pred, T const& new_value);

/// Replaces all elements satisfying specific criteria (for which predicate
/// \a f returns true) with \a new_value in the range [first, last).
/// Executed according to the policy.
///
/// Effects: Substitutes elements referred by the iterator it in the range
/// [first, last) with new_value, when the following corresponding
Expand Down Expand Up @@ -205,7 +207,8 @@ namespace hpx {
/// \a parallel_task_policy
/// and returns \a void otherwise.
///
template <typename ExPolicy, typename FwdIter, typename Pred, typename T>
template <typename ExPolicy, typename FwdIter, typename Pred,
typename T = typename std::iterator_traits<FwdIter>::value_type>
typename parallel::util::detail::algorithm_result<ExPolicy, void>::type
replace_if(ExPolicy&& policy, FwdIter first, FwdIter last, Pred&& pred,
T const& new_value);
Expand All @@ -223,17 +226,14 @@ namespace hpx {
/// \note Complexity: Performs exactly \a last - \a first applications of
/// the predicate.
///

/// of the algorithm may be parallelized and the manner
/// in which it executes the assignments.
/// \tparam InIter The type of the source iterators used (deduced).
/// This iterator type must meet the requirements of an
/// input iterator.
/// \tparam OutIter The type of the iterator representing the
/// destination range (deduced).
/// This iterator type must meet the requirements of an
/// output iterator.
/// \tparam T The type of the old and new values (deduced).
/// \tparam T The type of the old and new values (deduced).
///
/// \param first Refers to the beginning of the sequence of elements
/// the algorithm will be applied to.
Expand All @@ -246,19 +246,19 @@ namespace hpx {
/// The assignments in the parallel \a replace_copy algorithm
/// execute in sequential order in the calling thread.
///
///
/// \returns The \a replace_copy algorithm returns an
/// \a OutIter
/// The \a replace_copy algorithm returns the
/// Iterator to the element past the last element copied.
///
template <typename InIter, typename OutIter, typename T>
template <typename InIter, typename OutIter,
typename T = typename std::iterator_traits<OutIter>::value_type>
OutIter replace_copy(InIter first, InIter last, OutIter dest,
T const& old_value, T const& new_value);

/// Copies the all elements from the range [first, last) to another range
/// beginning at \a dest replacing all elements satisfying a specific
/// criteria with \a new_value.
/// criteria with \a new_value. Executed according to the policy.
///
/// Effects: Assigns to every iterator it in the range
/// [result, result + (last - first)) either new_value or
Expand Down Expand Up @@ -313,8 +313,9 @@ namespace hpx {
/// Iterator to the element past the last element copied.
///
template <typename ExPolicy, typename FwdIter1, typename FwdIter2,
typename T>
typename parallel::util::detail::algorithm_result<ExPolicy, FwdIter2>::type
typename T = typename std::iterator_traits<FwdIter2>::value_type>
typename parallel::util::detail::algorithm_result
<ExPolicy, FwdIter2>::type
replace_copy(ExPolicy&& policy, FwdIter1 first, FwdIter1 last,
FwdIter2 dest, T const& old_value, T const& new_value);

Expand Down Expand Up @@ -378,7 +379,8 @@ namespace hpx {
/// element in the destination range, one past the last element
/// copied.
///
template <typename InIter, typename OutIter, typename Pred, typename T>
template <typename InIter, typename OutIter, typename Pred,
typename T = typename std::iterator_traits<OutIter>::value_type>
OutIter replace_copy_if(InIter first, InIter last, OutIter dest,
Pred&& pred, T const& new_value);

Expand Down Expand Up @@ -408,8 +410,8 @@ namespace hpx {
/// forward iterator.
/// \tparam Pred The type of the function/function object to use
/// (deduced). Unlike its sequential form, the parallel
/// overload of \a equal requires \a F to meet the
/// requirements of \a CopyConstructible.
/// overload of \a replace_copy_if requires \a Pred to
/// meet the requirements of \a CopyConstructible.
/// (deduced).
/// \tparam T The type of the new values to replace (deduced).
///
Expand Down Expand Up @@ -460,8 +462,10 @@ namespace hpx {
/// copied.
///
template <typename ExPolicy, typename FwdIter1, typename FwdIter2,
typename Pred, typename T>
typename parallel::util::detail::algorithm_result<ExPolicy, FwdIter2>::type
typename Pred, typename T = typename std::iterator_traits
<FwdIter2>::value_type>
typename parallel::util::detail::algorithm_result
<ExPolicy, FwdIter2>::type
replace_copy_if(ExPolicy&& policy, FwdIter1 first, FwdIter1 last,
FwdIter2 dest, Pred&& pred, T const& new_value);

Expand Down
42 changes: 22 additions & 20 deletions libs/core/algorithms/include/hpx/parallel/algorithms/reverse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
namespace hpx {

/// Reverses the order of the elements in the range [first, last).
/// Behaves as if applying std::iter_swap to every pair of iterators
/// first+i, (last-i) - 1 for each non-negative i < (last-first)/2.
/// Behaves as if applying \a std::iter_swap to every pair of iterators
/// first+i, (\a last-i) - 1 for each non-negative i < (last-first)/2.
///
/// \note Complexity: Linear in the distance between \a first and \a last.
///
/// \tparam BidirIter The type of the source iterators used (deduced).
/// This iterator type must meet the requirements of an
/// \tparam BidirIter The type of the source iterators used (deduced).
/// This iterator type must meet the requirements of a
/// bidirectional iterator.
///
/// \param first Refers to the beginning of the sequence of elements
Expand All @@ -31,23 +31,24 @@ namespace hpx {
/// The assignments in the parallel \a reverse algorithm
/// execute in sequential order in the calling thread.
///
/// \returns The \a reverse algorithm returns a \a void.
/// \returns The \a reverse algorithm returns \a void.
///
template <typename BidirIter>
void reverse(BidirIter first, BidirIter last);

/// Reverses the order of the elements in the range [first, last).
/// Behaves as if applying std::iter_swap to every pair of iterators
/// Behaves as if applying \a std::iter_swap to every pair of iterators
/// first+i, (last-i) - 1 for each non-negative i < (last-first)/2.
/// Executed according to the policy.
///
/// \note Complexity: Linear in the distance between \a first and \a last.
///
/// \tparam ExPolicy The type of the execution policy to use (deduced).
/// It describes the manner in which the execution
/// of the algorithm may be parallelized and the manner
/// in which it executes the assignments.
/// \tparam BidirIter The type of the source iterators used (deduced).
/// This iterator type must meet the requirements of an
/// \tparam BidirIter The type of the source iterators used (deduced).
/// This iterator type must meet the requirements of a
/// bidirectional iterator.
///
/// \param policy The execution policy to use for the scheduling of
Expand Down Expand Up @@ -79,19 +80,19 @@ namespace hpx {

///////////////////////////////////////////////////////////////////////////
/// Copies the elements from the range [first, last) to another range
/// beginning at dest_first in such a way that the elements in the new
/// beginning at dest in such a way that the elements in the new
/// range are in reverse order.
/// Behaves as if by executing the assignment
/// *(dest_first + (last - first) - 1 - i) = *(first + i) once for each
/// *(dest + (last - first) - 1 - i) = *(first + i) once for each
/// non-negative i < (last - first)
/// If the source and destination ranges (that is, [first, last) and
/// [dest_first, dest_first+(last-first)) respectively) overlap, the
/// [dest, dest+(last-first)) respectively) overlap, the
/// behavior is undefined.
///
/// \note Complexity: Performs exactly \a last - \a first assignments.
///
/// \tparam BidirIter The type of the source iterators used (deduced).
/// This iterator type must meet the requirements of an
/// This iterator type must meet the requirements of a
/// bidirectional iterator.
/// \tparam OutIter The type of the iterator representing the
/// destination range (deduced).
Expand All @@ -117,14 +118,14 @@ namespace hpx {
OutIter reverse_copy(BidirIter first, BidirIter last, Outiter dest);

/// Copies the elements from the range [first, last) to another range
/// beginning at dest_first in such a way that the elements in the new
/// beginning at dest in such a way that the elements in the new
/// range are in reverse order.
/// Behaves as if by executing the assignment
/// *(dest_first + (last - first) - 1 - i) = *(first + i) once for each
/// *(dest + (last - first) - 1 - i) = *(first + i) once for each
/// non-negative i < (last - first)
/// If the source and destination ranges (that is, [first, last) and
/// [dest_first, dest_first+(last-first)) respectively) overlap, the
/// behavior is undefined.
/// [dest, dest+(last-first)) respectively) overlap, the
/// behavior is undefined. Executed according to the policy.
///
/// \note Complexity: Performs exactly \a last - \a first assignments.
///
Expand All @@ -133,11 +134,11 @@ namespace hpx {
/// of the algorithm may be parallelized and the manner
/// in which it executes the assignments.
/// \tparam BidirIter The type of the source iterators used (deduced).
/// This iterator type must meet the requirements of an
/// This iterator type must meet the requirements of a
/// bidirectional iterator.
/// \tparam FwdIter The type of the iterator representing the
/// destination range (deduced).
/// This iterator type must meet the requirements of an
/// This iterator type must meet the requirements of a
/// forward iterator.
///
/// \param policy The execution policy to use for the scheduling of
Expand Down Expand Up @@ -170,9 +171,10 @@ namespace hpx {
/// copied.
///
template <typename ExPolicy, typename BidirIter, typename FwdIter>
typename util::detail::algorithm_result<ExPolicy, FwdIter>::type
typename parallel::util::detail::algorithm_result
<ExPolicy, FwdIter>::type
reverse_copy(
ExPolicy&& policy, BidirIter first, BidirIter last, FwdIter dest_first);
ExPolicy&& policy, BidirIter first, BidirIter last, FwdIter dest);

} // namespace hpx

Expand Down
Loading