161std::vector< std::size_t >
lcpArray( E & ex ,
const S & T ,
162 const std::vector< std::size_t > & SA )
164 const std::size_t n = SA.size();
165 ADS_PRE( std::size_t( std::size( T ) ) == n );
166 if( ( ex.concurrency() == 1 ) || ( n < ( std::size_t( 1 ) << 15 ) ) )
169 std::vector< std::size_t > P( n );
172 [ & ]( std::size_t r ) { P[ SA[ r ] ] = r == 0 ? n : SA[ r - 1 ]; } ,
174 const std::size_t B = std::min( n , 4 * ex.concurrency() );
177 [ & ]( std::size_t b ) {
178 const std::size_t i0 = n * b / B , i1 = n * ( b + 1 ) / B;
180 for( std::size_t i = i0 ; i < i1 ; ++i ) {
181 const std::size_t j = P[ i ];
187 while( ( i + h < n ) && ( j + h < n ) && ( T[ i + h ] == T[ j + h ] ) )
195 std::vector< std::size_t > LCP( n - 1 );
197 ex , 0 , n - 1 , [ & ]( std::size_t r ) { LCP[ r ] = P[ SA[ r + 1 ] ]; } ,
206 const std::vector< I > & SA )
208 const std::size_t n = SA.size();
210 if( ( ex.concurrency() == 1 ) || ( n < ( std::size_t( 1 ) << 15 ) ) )
212 const auto * t =
reinterpret_cast< const unsigned char *
>( T.data() );
213 const auto P = std::make_unique_for_overwrite< I[] >( n );
216 [ & ]( std::size_t r ) { P[ SA[ r ] ] = r == 0 ? I( n ) : SA[ r - 1 ]; } ,
220 auto lcp = [ & ]( std::size_t i , std::size_t j , std::size_t h ) {
221 const std::size_t far = n - std::max( i , j ) ,
222 near = std::min( far , h + 4 );
223 while( ( h < near ) && ( t[ i + h ] == t[ j + h ] ) )
228 while( ( h < far ) && ( t[ i + h ] == t[ j + h ] ) )
233 std::memcpy( &a , t + i + h , 8 );
234 std::memcpy( &b , t + j + h , 8 );
236 if constexpr( std::endian::native == std::endian::little )
237 h += std::size_t( std::countr_zero( a ^ b ) ) / 8;
239 h += std::size_t( std::countl_zero( a ^ b ) ) / 8;
246 const std::size_t B = std::min( n , 4 * ex.concurrency() );
249 [ & ]( std::size_t b ) {
250 const std::size_t i0 = n * b / B , i1 = n * ( b + 1 ) / B;
251 constexpr std::size_t D = 16;
253 for( std::size_t i = i0 ; i < i1 ; ++i ) {
255 ADS::detail::prefetchLine(
256 t + std::min< std::size_t >( std::size_t( P[ i + D ] ) + h , n - 1 ) );
257 const std::size_t j = std::size_t( P[ i ] );
258 h = j == n ? 0 : lcp( i , j , h );
264 std::vector< I > LCP( n - 1 );
266 ex , 0 , n - 1 , [ & ]( std::size_t r ) { LCP[ r ] = P[ SA[ r + 1 ] ]; } ,
void parallelFor(E &ex, std::size_t first, std::size_t last, F &&f, std::size_t grain=kGrain, std::size_t blocks=kBlocks)
the calls f( i ) for each , in parallel
std::vector< std::size_t > lcpArray(E &ex, const S &T, const std::vector< std::size_t > &SA)
the LCP array of and of its suffix array on the threads of ex, entries (none if )
Definition ParallelText.h:161
std::vector< I > lcpArrayPhi(E &ex, std::string_view T, const std::vector< I > &SA)
the LCP array of the text of bytes and of its suffix array of indices of the type I,...
Definition ParallelText.h:205