|
ADS
Algorithms and Data Structures
|
The multikey quicksort of Bentley and Sedgewick, as chapter 7, Sorting Strings, of Ferragina's book presents it. More...
Files | |
| file | ADS/sort/MultikeyQuickSort.h |
| The multikey quicksort of Bentley and Sedgewick, as chapter 7, Sorting Strings, of Ferragina's book presents it: the quicksort of strings by one character at a time, a partition into three parts, the strings whose character \( d \) is smaller, equal and larger than that of the pivot, the equal part going on with the character \( d + 1 \) and the others with \( d \). | |
Functions | |
| template<StringStore Store> | |
| void | ADS::multikeyQuickSort (Store &&A) |
| the multikey quicksort of strings | |
| void | ADS::multikeyQuickSort (std::vector< std::string > &A) |
| multikeyQuickSort() above on a vector | |
| template<SortRange R, class... P> requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { multikeyQuickSort( v , std::forward< P >( p )... ); } | |
| decltype(auto) | ADS::multikeyQuickSort (R &&A, P &&... p) |
| multikeyQuickSort() 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 multikey quicksort of Bentley and Sedgewick, as chapter 7, Sorting Strings, of Ferragina's book presents it.
The definitions, the invariants and the costs of the area are in Theory of sorting.
| decltype(auto) ADS::multikeyQuickSort | ( | R && | A, |
| P &&... | p ) |
multikeyQuickSort() 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
|
inline |
multikeyQuickSort() above on a vector
| void ADS::multikeyQuickSort | ( | Store && | A | ) |
the multikey quicksort of strings
In pseudocode (Algorithm 7.1 of chapter 7, Sorting Strings, of Ferragina's book, with the middle string as the pivot), \( s[ d ] \) the character \( d \) of \( s \), \( -1 \) past its end:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{mkqs}( A , \mathit{lo} , \mathit{hi} , d ) \cr 2 & \quad \textbf{if}\ \mathit{hi} - \mathit{lo} \le 10\ \textbf{then} \ \text{insertion sort by the suffixes from } d;\ \textbf{return} \cr 3 & \quad v \gets A[ \lfloor ( \mathit{lo} + \mathit{hi} ) / 2 \rfloor ][ d ] \cr 4 & \quad \text{split } A[ \mathit{lo} .. \mathit{hi} - 1 ] \text{ into } \text{the parts of character } d \text{ below, at and above } v \cr 5 & \quad \mathit{lt} , \mathit{gt} \gets \text{the first places of the } \text{equal and of the larger part} \cr 6 & \quad \mathrm{mkqs}( A , \mathit{lo} , \mathit{lt} , d ) \cr 7 & \quad \textbf{if}\ v \ge 0\ \textbf{then}\ \mathrm{mkqs}( A , \mathit{lt} , \mathit{gt} , d + 1 ) \cr 8 & \quad \mathrm{mkqs}( A , \mathit{gt} , \mathit{hi} , d ) \cr 9 & \textbf{procedure}\ \mathrm{multikeyQuickSort}( A ) \cr 10 & \quad \mathrm{mkqs}( A , 0 , n , 0 ) \end{array}} \]