...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Pattern-defeating quicksort is available through two calls,
and pdqsort
.
Both have identical guarantees, behavior and overloads as std::sort,
with the exception of the C++17 parallel execution policy argument. Thus
you can simply replace a call to std::sort
with pdqsort_branchless
,
it is simply a faster implementation. It is almost always appropriate to
simply call pdqsort
and ignore pdqsort
.
pdqsort_branchless
runs significantly faster than pdqsort_branchless
for comparison functions that are branchless (for an explanation why see
'The Average Case' below), such as simple integer or float comparison,
and slightly slower when the comparison function contains branches. When
using an arithmetic type and a default comparison function (std::less
or std::greater)
pdqsort
automatically delegates to pdqsort
.
If you know that your custom comparison function is branchless and wish
to make use of this speedup call pdqsort_branchless
explicitly.
pdqsort_branchless