|
ADS
Algorithms and Data Structures
|
The in-place super scalar samplesort, beyond the book: sampleSort() splits the vector into up to 256 buckets by splitters drawn from a sample, in place with \( O( k b ) \) extra items for \( k \) buckets and blocks of \( b \) items (about 2 KiB), and sorts each bucket in the same way, those of at most 64 items by insertion. More...
#include "ADS/Contract.h"#include "ADS/sort/EngineeredQuickSorts.h"#include "ADS/sort/Sorted.h"#include <algorithm>#include <bit>#include <cstddef>#include <cstdint>#include <functional>#include <memory>#include <utility>#include <vector>#include "ADS/sort/impl/SampleSort.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::sampleSort (Store &&A, C less=C()) |
| the in-place super scalar samplesort of \( A \) by less | |
| template<class T, class C = std::less<>> | |
| void | ADS::sampleSort (std::vector< T > &A, C less=C()) |
| sampleSort() above on a vector | |
| template<SortRange R, class... P> requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { sampleSort( v , std::forward< P >( p )... ); } | |
| decltype(auto) | ADS::sampleSort (R &&A, P &&... p) |
| sampleSort() 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 in-place super scalar samplesort, beyond the book: sampleSort() splits the vector into up to 256 buckets by splitters drawn from a sample, in place with \( O( k b ) \) extra items for \( k \) buckets and blocks of \( b \) items (about 2 KiB), and sorts each bucket in the same way, those of at most 64 items by insertion.
It sorts by comparisons alone, so that it takes any order, and it is not stable.
Each item is read and written about twice per level, and with \( k = 256 \) there are about \( \lceil \log_{256}( n / 16 ) \rceil \) levels; the expected number of comparisons is \( n \log_2 n + O( n ) \), of which none is a branch in the classification. The buckets differ from \( n / k \) by a factor \( 1 + \epsilon \) with a probability that grows with \( \alpha \); a bucket larger than half the part, which only an unlucky sample gives, is sorted by pdqSort(), so that the worst case is \( O( n \log n ) \).
The contracts [see Contract.h]: the vector ends with the same items sorted, an audit. The functions are defined in SampleSort.tpp.