hpx/parallel/container_algorithms/nth_element.hpp¶
See Public API for a list of names and headers that are part of the public HPX API.
-
namespace
hpx
-
namespace
ranges
Functions
-
template<typename
RandomIt
, typenameSent
, typenamePred
, typenameProj
>
RandomItnth_element
(RandomIt first, RandomIt nth, Sent last, Pred &&pred, Proj &&proj)¶ nth_element is a partial sorting algorithm that rearranges elements in [first, last) such that the element pointed at by nth is changed to whatever element would occur in that position if [first, last) were sorted and all of the elements before this new nth element are less than or equal to the elements after the new nth element.
The comparison operations in the parallel
nth_element algorithm invoked without an execution policy object execute in sequential order in the calling thread.- Note
Complexity: Linear in std::distance(first, last) on average. O(N) applications of the predicate, and O(N log N) swaps, where N = last - first.
- Template Parameters
RandomIt
: The type of the source begin, nth, and end iterators used (deduced). This iterator type must meet the requirements of a random access iterator.Sent
: The type of the source sentinel (deduced). This sentinel type must be a sentinel for RandomIt.Pred
: Comparison function object which returns true if the first argument is less than the second.Proj
: The type of an optional projection function. This defaults to util::projection_identity
- Parameters
first
: Refers to the beginning of the sequence of elements the algorithm will be applied to.nth
: Refers to the iterator defining the sort partition pointlast
: Refers to sentinel value denoting the end of the sequence of elements the algorithm will be applied.pred
: Specifies the comparison function object which returns true if the first argument is less than (i.e. is ordered before) the second. The signature of this comparison function should be equivalent to:bool cmp(const Type1 &a, const Type2 &b);
The signature does not need to have const&, but the function must not modify the objects passed to it. The type must be such that an object of type
randomIt can be dereferenced and then implicitly converted to Type. This defaults to std::less<>.proj
: Specifies the function (or function object) which will be invoked for each of the elements as a projection operation before the actual predicate is invoked. This defaults to projection_identity.
- Return
The nth_element algorithm returns returns RandomIt. The nth_element algorithm returns an iterator equal to last.
-
template<typename
ExPolicy
, typenameRandomIt
, typenameSent
, typenamePred
, typenameProj
>
parallel::util::detail::algorithm_result_t<ExPolicy, RandomIt>nth_element
(ExPolicy &&policy, RandomIt first, RandomIt nth, Sent last, Pred &&pred, Proj &&proj)¶ nth_element is a partial sorting algorithm that rearranges elements in [first, last) such that the element pointed at by nth is changed to whatever element would occur in that position if [first, last) were sorted and all of the elements before this new nth element are less than or equal to the elements after the new nth element.
The comparison operations in the parallel
nth_element invoked with an execution policy object of type sequenced_policy execute in sequential order in the calling thread.- Note
Complexity: Linear in std::distance(first, last) on average. O(N) applications of the predicate, and O(N log N) swaps, where N = last - first.
- Template Parameters
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.RandomIt
: The type of the source begin, nth, and end iterators used (deduced). This iterator type must meet the requirements of a random access iterator.Sent
: The type of the source sentinel (deduced). This sentinel type must be a sentinel for RandomIt.Pred
: Comparison function object which returns true if the first argument is less than the second.Proj
: The type of an optional projection function. This defaults to util::projection_identity
- Parameters
policy
: The execution policy to use for the scheduling of the iterations.first
: Refers to the beginning of the sequence of elements the algorithm will be applied to.nth
: Refers to the iterator defining the sort partition pointlast
: Refers to sentinel value denoting the end of the sequence of elements the algorithm will be applied.pred
: Specifies the comparison function object which returns true if the first argument is less than (i.e. is ordered before) the second. The signature of this comparison function should be equivalent to:bool cmp(const Type1 &a, const Type2 &b);
The signature does not need to have const&, but the function must not modify the objects passed to it. The type must be such that an object of type
randomIt can be dereferenced and then implicitly converted to Type. This defaults to std::less<>.proj
: Specifies the function (or function object) which will be invoked for each of the elements as a projection operation before the actual predicate is invoked. This defaults to projection_identity.
The assignments in the parallel nth_element algorithm invoked with an execution policy object of type parallel_policy or parallel_task_policy are permitted to execute in an unordered fashion in unspecified threads, and indeterminately sequenced within each thread.
- Return
The partition algorithm returns a hpx::future<RandomIt> if the execution policy is of type parallel_task_policy and returns RandomIt otherwise. The nth_element algorithm returns an iterator equal to last.
-
template<typename
Rng
, typenamePred
, typenameProj
>
hpx::traits::range_iterator_t<Rng>nth_element
(Rng &&rng, hpx::traits::range_iterator_t<Rng> nth, Pred &&pred, Proj &&proj)¶ nth_element is a partial sorting algorithm that rearranges elements in [first, last) such that the element pointed at by nth is changed to whatever element would occur in that position if [first, last) were sorted and all of the elements before this new nth element are less than or equal to the elements after the new nth element.
The comparison operations in the parallel
nth_element algorithm invoked without an execution policy object execute in sequential order in the calling thread.- Note
Complexity: Linear in std::distance(first, last) on average. O(N) applications of the predicate, and O(N log N) swaps, where N = last - first.
- Template Parameters
Rng
: The type of the source range used (deduced). The iterators extracted from this range type must meet the requirements of an random access iterator.Pred
: Comparison function object which returns true if the first argument is less than the second.Proj
: The type of an optional projection function. This defaults to util::projection_identity
- Parameters
rng
: Refers to the sequence of elements the algorithm will be applied to.nth
: Refers to the iterator defining the sort partition pointpred
: Specifies the comparison function object which returns true if the first argument is less than (i.e. is ordered before) the second. The signature of this comparison function should be equivalent to:bool cmp(const Type1 &a, const Type2 &b);
The signature does not need to have const&, but the function must not modify the objects passed to it. The type must be such that an object of type
randomIt can be dereferenced and then implicitly converted to Type. This defaults to std::less<>.proj
: Specifies the function (or function object) which will be invoked for each of the elements as a projection operation before the actual predicate is invoked. This defaults to projection_identity.
- Return
The nth_element algorithm returns returns hpx::traits::range_iterator_t<Rng>. The nth_element algorithm returns an iterator equal to last.
-
template<typename
ExPolicy
, typenameRng
, typenamePred
, typenameProj
>
parallel::util::detail::algorithm_result_t<ExPolicy, hpx::traits::range_iterator_t<Rng>>nth_element
(ExPolicy &&policy, Rng &&rng, hpx::traits::range_iterator_t<Rng> nth, Pred &&pred, Proj &&proj)¶ nth_element is a partial sorting algorithm that rearranges elements in [first, last) such that the element pointed at by nth is changed to whatever element would occur in that position if [first, last) were sorted and all of the elements before this new nth element are less than or equal to the elements after the new nth element.
The comparison operations in the parallel
nth_element invoked with an execution policy object of type sequenced_policy execute in sequential order in the calling thread.- Note
Complexity: Linear in std::distance(first, last) on average. O(N) applications of the predicate, and O(N log N) swaps, where N = last - first.
- Template Parameters
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.Rng
: The type of the source range used (deduced). The iterators extracted from this range type must meet the requirements of an random access iterator.Pred
: Comparison function object which returns true if the first argument is less than the second.Proj
: The type of an optional projection function. This defaults to util::projection_identity
- Parameters
policy
: The execution policy to use for the scheduling of the iterations.rng
: Refers to the sequence of elements the algorithm will be applied to.nth
: Refers to the iterator defining the sort partition pointpred
: Specifies the comparison function object which returns true if the first argument is less than (i.e. is ordered before) the second. The signature of this comparison function should be equivalent to:bool cmp(const Type1 &a, const Type2 &b);
The signature does not need to have const&, but the function must not modify the objects passed to it. The type must be such that an object of type
randomIt can be dereferenced and then implicitly converted to Type. This defaults to std::less<>.proj
: Specifies the function (or function object) which will be invoked for each of the elements as a projection operation before the actual predicate is invoked. This defaults to projection_identity.
The assignments in the parallel nth_element algorithm invoked with an execution policy object of type parallel_policy or parallel_task_policy are permitted to execute in an unordered fashion in unspecified threads, and indeterminately sequenced within each thread.
- Return
The partition algorithm returns a hpx::future<hpx::traits::range_iterator_t<Rng>> if the execution policy is of type parallel_task_policy and returns hpx::traits::range_iterator_t<Rng> otherwise. The nth_element algorithm returns an iterator equal to last.
-
template<typename
-
namespace