template<class T, class Compare = std::less< T >>
class ADS::WordRangeMinimum< T, Compare >
the leftmost minima of the ranges of an array, by the order less()
template<class T, class Compare = std::less< T >>
the structure on \( A \), in \( O( n ) \)
In pseudocode (the in-word stacks, beyond the book), \( S \) the table of the minima of the blocks as in SparseTable:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{build}( A ) \cr
2 & \quad \textbf{foreach}\ \text{block of 64 items from } b\ \textbf{do}
\cr
3 & \qquad s \gets 0 \cr
4 & \qquad \textbf{for}\ t \gets b\ \textbf{to}\ \text{the end of the }
\text{block}\ \textbf{do} \cr
5 & \qquad\quad s \gets s \text{ without the places of the items }
\text{larger than } A[ t ] \cr
6 & \qquad\quad s \gets s + 2^{t - b};\ \mathit{mask}[ t ] \gets s \cr
7 & \qquad \text{the minima of the prefixes and of the suffixes of the }
\text{block, by two scans} \cr
8 & \quad S \gets \text{the sparse table of the minima of the blocks}
\end{array}}
\]
- Precondition
- \( n < 2^{32} \)
template<class T, class Compare = std::less< T >>
the place of the leftmost minimum of \( A[ i .. j ] \), \( O( 1 ) \)
In pseudocode (the in-word stacks, beyond the book):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{query}( i , j ) \cr
2 & \quad b_i \gets \lfloor i / 64 \rfloor;\ b_j \gets \lfloor j / 64
\rfloor \cr
3 & \quad \textbf{if}\ b_i = b_j\ \textbf{then return}\ 64 b_i +
\mathrm{ctz}( \mathit{mask}[ j ] \wedge \neg ( 2^{i \bmod 64} - 1 )
) \cr
4 & \quad m \gets \text{the minimum of the suffix of block } b_i
\text{ from } i \cr
5 & \quad \textbf{if}\ b_j > b_i + 1\ \textbf{then}\ m \gets \text{the }
\text{better of } m \text{ and } S.\mathrm{query}( b_i + 1 , b_j - 1
) \cr
6 & \quad \textbf{return}\ \text{the better of } m \text{ and the }
\text{minimum of the prefix of } b_j \text{ to } j
\end{array}}
\]
- Precondition
- \( i \le j < n \)
- Postcondition
- a leftmost minimum of \( A[ i .. j ] \) (audit)