ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ParallelText.h File Reference

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 ] ] \). More...

#include "ADS/Contract.h"
#include "ADS/memory/Prefetch.h"
#include "ADS/parallel/Executor.h"
#include "ADS/string/SuffixArray.h"
#include "ADS/string/SuffixSorting.h"
#include <algorithm>
#include <bit>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <memory>
#include <string_view>
#include <vector>

Go to the source code of this file.

Namespaces

namespace  ADS

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]

Detailed description

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 ] ] \).

The first and the last steps are parallel loops of \( n \) scattered moves. The second is the scan of Kasai et al. along the text, which reads \( T \) in its order and uses \( \mathit{PLCP}[ i ] \ge \mathit{PLCP}[ i - 1 ] - 1 \) to resume each comparison where the previous one stopped, \( O( n ) \) comparisons in all; the text is cut into \( 4 p \) parts, and each part starts its scan from \( h = 0 \), which costs at most the largest lcp more per part, so that the result is the same and the work \( O( n + p \max_i \mathit{PLCP}[ i ] ) \) (on a text of one repeated symbol the parts gain nothing, since then the lcp are as long as the text). The scan by the text order reads \( \Phi[ i ] \) and \( T[ \Phi[ i ] + h ] \) at random once per suffix, where the algorithm of Kasai reads the rank and the suffix array at random.

lcpArrayPhi( ex , T , SA ) does the same on a text of bytes and a suffix array of indices of the type I (e.g., 32 bits), the result of lcpArrayPhi( T , SA ) [see SuffixSorting.h]: its scans compare the first 4 symbols one by one and then 8 at a time by a load of 8 bytes, the first different byte found by the trailing zeros of the exclusive or, and fetch the text at \( \Phi[ i + 16 ] \) ahead of its use.

The contracts [see Contract.h]: \( \mathit{SA} \) is the suffix array of \( T \) (an audit); the result is the LCP array (an audit).

See also
J. Kärkkäinen, G. Manzini, S. J. Puglisi, Permuted longest-common- prefix array, Annual Symposium on Combinatorial Pattern Matching (CPM), LNCS 5577, 181-192, 2009, doi:10.1007/978-3-642-02441-2_17
T. Kasai, G. Lee, H. Arimura, S. Arikawa, K. Park, Linear-time longest-common-prefix computation in suffix arrays and its applications, Annual Symposium on Combinatorial Pattern Matching (CPM), LNCS 2089, 181-192, 2001, doi:10.1007/3-540-48194-X_17
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa