ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::WordRangeMinimum< T, Compare > Class Template Reference

the leftmost minima of the ranges of an array, by the order less() More...

#include <ADS/search/WordRangeMinimum.h>

Public types

using value_type = T
 the type of the items
using size_type = std::size_t
 the type of the sizes
using difference_type = std::ptrdiff_t
 the type of the distances
using const_reference = const T &
 a reference to an item
using reference = const_reference
 the same, constant
using const_iterator = typename std::vector< T >::const_iterator
 an iterator on the items
using iterator = const_iterator
 the same, constant

Public member functions

 WordRangeMinimum (void)=default
 an empty structure
 WordRangeMinimum (std::vector< T > A, Compare less={})
 the structure on \( A \), in \( O( n ) \)
std::size_t query (std::size_t i, std::size_t j) const
 the place of the leftmost minimum of \( A[ i .. j ] \), \( O( 1 ) \)
std::size_t size (void) const
 the number \( n \) of the items
const T & operator[] (std::size_t i) const
 the item of place \( i \)
const_iterator begin (void) const
 the first item
const_iterator end (void) const
 past the last item
const_iterator cbegin (void) const
 the first item
const_iterator cend (void) const
 past the last item

Detailed description

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()

Member typedef documentation

◆ const_iterator

template<class T, class Compare = std::less< T >>
using ADS::WordRangeMinimum< T, Compare >::const_iterator = typename std::vector< T >::const_iterator

an iterator on the items

◆ const_reference

template<class T, class Compare = std::less< T >>
using ADS::WordRangeMinimum< T, Compare >::const_reference = const T &

a reference to an item

◆ difference_type

template<class T, class Compare = std::less< T >>
using ADS::WordRangeMinimum< T, Compare >::difference_type = std::ptrdiff_t

the type of the distances

◆ iterator

template<class T, class Compare = std::less< T >>
using ADS::WordRangeMinimum< T, Compare >::iterator = const_iterator

the same, constant

◆ reference

template<class T, class Compare = std::less< T >>
using ADS::WordRangeMinimum< T, Compare >::reference = const_reference

the same, constant

◆ size_type

template<class T, class Compare = std::less< T >>
using ADS::WordRangeMinimum< T, Compare >::size_type = std::size_t

the type of the sizes

◆ value_type

template<class T, class Compare = std::less< T >>
using ADS::WordRangeMinimum< T, Compare >::value_type = T

the type of the items

Constructor and destructor documentation

◆ WordRangeMinimum() [1/2]

template<class T, class Compare = std::less< T >>
ADS::WordRangeMinimum< T, Compare >::WordRangeMinimum ( void )
default

an empty structure

◆ WordRangeMinimum() [2/2]

template<class T, class Compare = std::less< T >>
ADS::WordRangeMinimum< T, Compare >::WordRangeMinimum ( std::vector< T > A,
Compare less = {} )
explicit

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} \)

Member function documentation

◆ begin()

template<class T, class Compare = std::less< T >>
const_iterator ADS::WordRangeMinimum< T, Compare >::begin ( void ) const
inlinenodiscard

the first item

◆ cbegin()

template<class T, class Compare = std::less< T >>
const_iterator ADS::WordRangeMinimum< T, Compare >::cbegin ( void ) const
inlinenodiscard

the first item

◆ cend()

template<class T, class Compare = std::less< T >>
const_iterator ADS::WordRangeMinimum< T, Compare >::cend ( void ) const
inlinenodiscard

past the last item

◆ end()

template<class T, class Compare = std::less< T >>
const_iterator ADS::WordRangeMinimum< T, Compare >::end ( void ) const
inlinenodiscard

past the last item

◆ operator[]()

template<class T, class Compare = std::less< T >>
const T & ADS::WordRangeMinimum< T, Compare >::operator[] ( std::size_t i) const
nodiscard

the item of place \( i \)

Precondition
\( i < n \)

◆ query()

template<class T, class Compare = std::less< T >>
std::size_t ADS::WordRangeMinimum< T, Compare >::query ( std::size_t i,
std::size_t j ) const
nodiscard

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)

◆ size()

template<class T, class Compare = std::less< T >>
std::size_t ADS::WordRangeMinimum< T, Compare >::size ( void ) const
inlinenodiscard

the number \( n \) of the items


The documentation for this class was generated from the following file: