Skip to content

Commit

Permalink
Separate sort and stable_sort backends
Browse files Browse the repository at this point in the history
  • Loading branch information
alugowski committed Dec 14, 2023
1 parent cddf3a9 commit f88bcdf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
6 changes: 4 additions & 2 deletions include/poolstl/algorithm
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ namespace std {
return;
}

poolstl::internal::parallel_sort(std::forward<ExecPolicy>(policy), first, last, comp, false);
poolstl::internal::parallel_sort(std::forward<ExecPolicy>(policy), first, last, comp,
std::sort<RandIt, Compare>);
}

/**
Expand All @@ -247,7 +248,8 @@ namespace std {
return;
}

poolstl::internal::parallel_sort(std::forward<ExecPolicy>(policy), first, last, comp, true);
poolstl::internal::parallel_sort(std::forward<ExecPolicy>(policy), first, last, comp,
std::stable_sort<RandIt, Compare>);
}

/**
Expand Down
12 changes: 4 additions & 8 deletions include/poolstl/internal/ttp_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,16 @@ namespace poolstl {
*
* @param stable Whether to use std::stable_sort or std::sort
*/
template <class ExecPolicy, class RandIt, class Compare>
void parallel_sort(ExecPolicy &&policy, RandIt first, RandIt last, Compare comp, bool stable) {
template <class ExecPolicy, class RandIt, class Compare, class SortFunc>
void parallel_sort(ExecPolicy &&policy, RandIt first, RandIt last, Compare comp, SortFunc sortfunc) {
if (first == last) {
return;
}

// Sort chunks in parallel
auto futures = parallel_chunk_for_gen(std::forward<ExecPolicy>(policy), first, last,
[&comp, stable] (RandIt chunk_first, RandIt chunk_last) {
if (stable) {
std::stable_sort(chunk_first, chunk_last, comp);
} else {
std::sort(chunk_first, chunk_last, comp);
}
[&comp, sortfunc] (RandIt chunk_first, RandIt chunk_last) {
sortfunc(chunk_first, chunk_last, comp);
return std::make_pair(chunk_first, chunk_last);
});

Expand Down

0 comments on commit f88bcdf

Please sign in to comment.