# hpx::partial_sort#

See Public API for a list of names and headers that are part of the public HPX API.

namespace hpx

Functions

template<typename RandIter, typename Comp = hpx::parallel::detail::less>
RandIter partial_sort(RandIter first, RandIter middle, RandIter last, Comp &&comp = Comp())#

Places the first middle - first elements from the range [first, last) as sorted with respect to comp into the range [first, middle). The rest of the elements in the range [middle, last) are placed in an unspecified order.

Note

Complexity: Approximately (last - first) * log(middle - first) comparisons.

Template Parameters
• RandIter – The type of the source begin, middle, and end iterators used (deduced). This iterator type must meet the requirements of a random access iterator.

• Comp – The type of the function/function object to use (deduced). Comp defaults to detail::less.

Parameters
• first – Refers to the beginning of the sequence of elements the algorithm will be applied to.

• middle – Refers to the middle of the sequence of elements the algorithm will be applied to.

• last – Refers to the end of the sequence of elements the algorithm will be applied to.

• comp – comp is a callable object. The return value of the INVOKE operation applied to an object of type Comp, when contextually converted to bool, yields true if the first argument of the call is less than the second, and false otherwise. It is assumed that comp will not apply any non-constant function through the dereferenced iterator. It defaults to detail::less.

Returns

The partial_sort algorithm returns a RandIter that refers to last.

template<typename ExPolicy, typename RandIter, typename Comp = hpx::parallel::detail::less>
parallel::util::detail::algorithm_result_t<ExPolicy, RandIter> partial_sort(ExPolicy &&policy, RandIter first, RandIter middle, RandIter last, Comp &&comp = Comp())#

Places the first middle - first elements from the range [first, last) as sorted with respect to comp into the range [first, middle). The rest of the elements in the range [middle, last) are placed in an unspecified order.

Note

Complexity: Approximately (last - first) * log(middle - first) comparisons.

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 applies user-provided function objects.

• RandIter – The type of the source begin, middle, and end iterators used (deduced). This iterator type must meet the requirements of a random access iterator.

• Comp – The type of the function/function object to use (deduced). Comp defaults to detail::less.

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.

• middle – Refers to the middle of the sequence of elements the algorithm will be applied to.

• last – Refers to the end of the sequence of elements the algorithm will be applied to.

• comp – comp is a callable object. The return value of the INVOKE operation applied to an object of type Comp, when contextually converted to bool, yields true if the first argument of the call is less than the second, and false otherwise. It is assumed that comp will not apply any non-constant function through the dereferenced iterator. It defaults to detail::less.

Returns

The partial_sort algorithm returns a hpx::future<RandIter> if the execution policy is of type sequenced_task_policy or parallel_task_policy and returns RandIter otherwise. The iterator returned refers to last.