|
ADS
Algorithms and Data Structures
|
The pattern-defeating quicksort, beyond the book and beyond the quicksorts of Ferragina's book, which are in EngineeredQuickSorts.h [see EngineeredQuickSorts.h, which includes this header]: More...
#include "ADS/Contract.h"#include "ADS/sort/EngineeredQuickSorts.h"#include "ADS/sort/InsertionSort.h"#include "ADS/sort/Sorted.h"#include <algorithm>#include <bit>#include <cstddef>#include <cstdint>#include <functional>#include <type_traits>#include <utility>#include <vector>#include "ADS/sort/impl/PdqSort.tpp"Go to the source code of this file.
Namespaces | |
| namespace | ADS |
Functions | |
| template<SortStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>> | |
| void | ADS::pdqSort (Store &&A, C less=C()) |
| the pattern-defeating quicksort | |
| template<class T, class C = std::less<>> | |
| void | ADS::pdqSort (std::vector< T > &A, C less=C()) |
| pdqSort() above on a vector | |
| template<SortRange R, class... P> requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { pdqSort( v , std::forward< P >( p )... ); } | |
| decltype(auto) | ADS::pdqSort (R &&A, P &&... p) |
| pdqSort() on the range \( A \) [see SortRange], the other arguments as for a vector: in place on the span of its items if \( A \) is contiguous, through a vector of its items otherwise, since the code of the sort reads the items by their addresses | |
The pattern-defeating quicksort, beyond the book and beyond the quicksorts of Ferragina's book, which are in EngineeredQuickSorts.h [see EngineeredQuickSorts.h, which includes this header]:
It sorts in place and is not stable; the recursion goes into the left part and loops on the right one, the other partitions leaving at most \( 7 / 8 \) of the items on each side, so that the stack stays \( O( \log n ) \). Besides its own use, pdqSort() is the engine of sort() [see Sort.h] for the short vectors, for few distinct keys and for the items that no faster route takes, and it stays so also where Boost is found: boost::sort::pdqsort is no slower on the benchmark of the sorts, and a program that wants it calls it directly.
The contracts [see Contract.h]: the sort ends with the same items sorted, an audit. The functions are defined in PdqSort.tpp.