|
ADS
Algorithms and Data Structures
|
The parallel LCP array, beyond the book. More...
Files | |
| file | ADS/parallel/ParallelText.h |
| The parallel LCP array, beyond the book: lcpArray( ex , T , SA ) is the array of lcpArray( T , SA ) [see SuffixArray.h], the longest common prefixes of the suffixes adjacent in the suffix array, on the threads of an executor [see Executor.h], by the permuted LCP of Kärkkäinen, Manzini and Puglisi: \( \Phi[ \mathit{SA}[ r ] ] = \mathit{SA}[ r - 1 ] \), the suffix before each one in the order of the suffix array, then the permuted array \( \mathit{PLCP}[ i ] = \mathrm{lcp}( i , \Phi[ i ] ) \) in the order of the text, and last \( \mathit{LCP}[ r - 1 ] = \mathit{PLCP}[ \mathit{SA}[ r ] ] \). | |
Functions | |
| template<Executor E, class S> | |
| std::vector< std::size_t > | ADS::lcpArray (E &ex, const S &T, const std::vector< std::size_t > &SA) |
| the LCP array of \( T \) and of its suffix array \( \mathit{SA} \) on the threads of ex, \( n - 1 \) entries (none if \( n < 2 \)) | |
| template<Executor E, class I> | |
| std::vector< I > | ADS::lcpArrayPhi (E &ex, std::string_view T, const std::vector< I > &SA) |
| the LCP array of the text \( T \) of bytes and of its suffix array \( \mathit{SA} \) of indices of the type I, on the threads of ex, the result of lcpArrayPhi( T , SA ) [see SuffixSorting.h] | |
The parallel LCP array, beyond the book.
The definitions, the invariants and the costs of the area are in Theory of parallelism.
|
nodiscard |
the LCP array of \( T \) and of its suffix array \( \mathit{SA} \) on the threads of ex, \( n - 1 \) entries (none if \( n < 2 \))
In pseudocode (the permuted LCP of Kärkkäinen, Manzini and Puglisi on the scan of Kasai et al., beyond the book), \( T[ 0 .. n - 1 ] \) and \( \mathit{SA}[ 0 .. n - 1 ] \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{lcpArray}( \mathit{ex} , T , \mathit{SA} ) \cr 2 & \quad \textbf{if}\ p = 1\ \textbf{or}\ n < 2^{15} \ \textbf{then return}\ \mathrm{lcpArray}( T , \mathit{SA} ) \cr 3 & \quad \textbf{for}\ r \gets 0\ \textbf{to}\ n - 1 \ \textbf{do in parallel}\ \Phi[ \mathit{SA}[ r ] ] \gets \mathit{SA}[ r - 1 ]\quad \triangleright\ \textbf{nil}\ \text{for } r = 0 \cr 4 & \quad B \gets \min\{ n , 4 p \} \cr 5 & \quad \textbf{for}\ b \gets 0\ \textbf{to}\ B - 1 \ \textbf{do in parallel} \cr 6 & \qquad h \gets 0 \cr 7 & \qquad \textbf{for}\ i \gets \lfloor n b / B \rfloor\ \textbf{to} \ \lfloor n ( b + 1 ) / B \rfloor - 1\ \textbf{do} \cr 8 & \qquad\quad j \gets \Phi[ i ] \cr 9 & \qquad\quad \textbf{if}\ j = \textbf{nil}\ \textbf{then}\ h \gets 0; \ \mathit{PLCP}[ i ] \gets 0;\ \textbf{continue} \cr 10 & \qquad\quad \textbf{while}\ i + h < n\ \textbf{and}\ j + h < n \ \textbf{and}\ T[ i + h ] = T[ j + h ]\ \textbf{do}\ h \gets h + 1 \cr 11 & \qquad\quad \mathit{PLCP}[ i ] \gets h;\ h \gets \max\{ h - 1 , 0 \} \cr 12 & \quad \textbf{for}\ r \gets 0\ \textbf{to}\ n - 2 \ \textbf{do in parallel}\ \mathit{LCP}[ r ] \gets \mathit{PLCP}[ \mathit{SA}[ r + 1 ] ] \cr 13 & \quad \textbf{return}\ \mathit{LCP} \end{array}} \]
|
nodiscard |
the LCP array of the text \( T \) of bytes and of its suffix array \( \mathit{SA} \) of indices of the type I, on the threads of ex, the result of lcpArrayPhi( T , SA ) [see SuffixSorting.h]
In pseudocode (beyond the book), that of lcpArray() above with its line 10 comparing 8 bytes at a time:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 10 & \qquad\quad h \gets \mathrm{lcp}( i , j , h )\quad \triangleright \ \text{4 bytes one by one, then words of 8 bytes} \cr 11 & \textbf{function}\ \mathrm{lcp}( i , j , h ) \cr 12 & \quad \mathit{far} \gets n - \max\{ i , j \} \cr 13 & \quad \textbf{while}\ h < \min\{ \mathit{far} , h_0 + 4 \} \ \textbf{and}\ T[ i + h ] = T[ j + h ]\ \textbf{do}\ h \gets h + 1\quad \triangleright\ h_0 \text{ the } h \text{ given} \cr 14 & \quad \textbf{if}\ \text{all 4 matched}\ \textbf{then} \cr 15 & \qquad \textbf{while}\ h + 8 \le \mathit{far}\ \textbf{and}\ T[ i + h .. i + h + 7 ] = T[ j + h .. j + h + 7 ]\ \textbf{do}\ h \gets h + 8 \cr 16 & \qquad \textbf{if}\ h + 8 \le \mathit{far}\ \textbf{then}\ h \gets h + \text{the first byte where they differ} \cr 17 & \qquad \textbf{else while}\ h < \mathit{far}\ \textbf{and}\ T[ i + h ] = T[ j + h ]\ \textbf{do}\ h \gets h + 1 \cr 18 & \quad \textbf{return}\ h \end{array}} \]