ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::LceIndex< I > Class Template Reference

the longest common extensions of the suffixes of a text, \( O( 1 ) \) each, on unsigned integers I of 32 or 64 bits More...

#include <ADS/string/LongestCommonExtension.h>

Public member functions

 LceIndex (std::string_view T)
 the index of \( T \) (a copy of it), in \( O( n ) \) time but for the sparse table of the groups
std::size_t lce (std::size_t i, std::size_t j) const
 the length of the longest common prefix of the suffixes \( i \) and \( j \)
std::size_t size (void) const
 the length \( n \) of the text

Detailed description

template<class I = std::uint32_t>
requires ( std::same_as< I , std::uint32_t > || std::same_as< I , std::uint64_t > )
class ADS::LceIndex< I >

the longest common extensions of the suffixes of a text, \( O( 1 ) \) each, on unsigned integers I of 32 or 64 bits

Constructor and destructor documentation

◆ LceIndex()

template<class I = std::uint32_t>
ADS::LceIndex< I >::LceIndex ( std::string_view T)
explicit

the index of \( T \) (a copy of it), in \( O( n ) \) time but for the sparse table of the groups

In pseudocode (the words of Alstrup, Gavoille, Kaplan and Rauhe and the sparse tables, beyond the book), blocks of 16 entries of \( \mathit{LCP} \) and groups of 64 blocks:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{LceIndex}( T ) \cr 2 & \quad \mathit{SA} \gets \mathrm{suffixArray}( T );\ \mathit{LCP} \gets \mathrm{lcpArrayPhi}( T , \mathit{SA} ) \cr 3 & \quad \textbf{for}\ r \gets 0\ \textbf{to}\ n - 1\ \textbf{do} \ \mathit{SA}^{-1}[ \mathit{SA}[ r ] ] \gets r \cr 4 & \quad \textbf{foreach}\ \text{block starting at } s\ \textbf{do} \cr 5 & \qquad M \gets 0 \cr 6 & \qquad \textbf{foreach}\ \text{entry } r \text{ of the block} \ \textbf{do} \cr 7 & \qquad\quad \textbf{while}\ M \ne 0\ \textbf{and}\ \mathit{LCP}[ s + \text{the highest bit of } M ] \ge \mathit{LCP}[ r ]\ \textbf{do} \cr 8 & \qquad\qquad \text{clear the highest bit of } M \cr 9 & \qquad\quad \text{set the bit } r - s \text{ of } M;\ M_r \gets M \cr 10 & \qquad \text{the minimum of the block} \gets \mathit{LCP}[ s + \mathrm{ctz}( M ) ] \cr 11 & \quad \textbf{foreach}\ \text{group}\ \textbf{do}\ \text{the } \text{sparse table of the minima of its 64 blocks} \cr 12 & \quad \text{the sparse table of the minima of the groups} \end{array}} \]

Precondition
\( |T| < 2^{31} \) if I has 32 bits

Member function documentation

◆ lce()

template<class I = std::uint32_t>
std::size_t ADS::LceIndex< I >::lce ( std::size_t i,
std::size_t j ) const
nodiscard

the length of the longest common prefix of the suffixes \( i \) and \( j \)

In pseudocode (Ilie, Navarro and Tinta for the direct comparison, beyond the book), \( \mathit{far} = n - \max( i , j ) \) the longest possible extension:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{lce}( i , j ) \cr 2 & \quad \textbf{if}\ i = j\ \textbf{then return}\ n - i \cr 3 & \quad \textbf{for}\ h \gets 0 \text{ by chunks of 32 (or 8) } \textbf{while}\ h < 64\ \textbf{do} \cr 4 & \qquad d \gets \text{the first mismatch of } T[ i + h .. ] \text{ and } T[ j + h .. ] \text{ in the chunk} \cr 5 & \qquad \textbf{if}\ \text{there is one}\ \textbf{then return}\ \min\{ h + d , \mathit{far} \} \cr 6 & \qquad \textbf{if}\ h + \text{the chunk} \ge \mathit{far} \ \textbf{then return}\ \mathit{far} \cr 7 & \quad a \gets \min\{ \mathit{SA}^{-1}[ i ] , \mathit{SA}^{-1}[ j ] \};\ b \gets \max\{ \mathit{SA}^{-1}[ i ] , \mathit{SA}^{-1}[ j ] \} \cr 8 & \quad \textbf{return}\ \min\{ \mathit{LCP}[ a .. b - 1 ] \} \text{ by the words of the two end blocks and the sparse tables} \end{array}} \]

Precondition
\( i \) and \( j \) are at most size()
Postcondition
the lcp of the two suffixes (audit)

◆ size()

template<class I = std::uint32_t>
std::size_t ADS::LceIndex< I >::size ( void ) const
inlinenodiscard

the length \( n \) of the text


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