|
ADS
Algorithms and Data Structures
|
the comparator to pass to a sort, by value: a pointer to the adversary, which must outlive it More...
#include <ADS/sort/QuicksortAdversary.h>
Public member functions | |
| Less (QuicksortAdversary &a) | |
| the comparator of the adversary \( a \) | |
| bool | operator() (std::size_t x, std::size_t y) const |
| true if the value of \( x \) is smaller than that of \( y \), after freezing one of them if both are gas | |
the comparator to pass to a sort, by value: a pointer to the adversary, which must outlive it
|
inlineexplicit |
the comparator of the adversary \( a \)
| bool ADS::QuicksortAdversary::Less::operator() | ( | std::size_t | x, |
| std::size_t | y ) const |
true if the value of \( x \) is smaller than that of \( y \), after freezing one of them if both are gas
In pseudocode (McIlroy's adversary, beyond the book), \( c \) the candidate for the pivot and \( v \) the values, \( \infty \) the gas:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{less}( x , y ) \cr 2 & \quad \textbf{if}\ v[ x ] = v[ y ] = \infty\ \textbf{then} \ \text{freeze } x \text{ if } x = c \text{, else } y \text{, to the next value} \cr 3 & \quad \textbf{if}\ v[ x ] = \infty\ \textbf{then}\ c \gets x \ \textbf{else if}\ v[ y ] = \infty\ \textbf{then}\ c \gets y \cr 4 & \quad \textbf{return}\ v[ x ] < v[ y ] \end{array}} \]