136#ifndef __ADS_StringSearch
137 #define __ADS_StringSearch
154#include <string_view>
162#ifndef ADS_SEARCH_SIMD
163 #define ADS_SEARCH_SIMD ADS_SIMD
165#if ADS_SEARCH_SIMD && ! ADS_SIMD
166 #error "ADS_SEARCH_SIMD = 1 needs ADS_WITH_HIGHWAY and no ADS_SIMD_SCALAR"
187 static constexpr std::size_t
npos = std::string_view::npos;
191 static constexpr std::size_t
kSkip = 64;
263 [[nodiscard]] std::size_t
find( std::string_view T ,
264 std::size_t from = 0 )
const;
269 [[nodiscard]] std::vector< std::size_t >
findAll( std::string_view T )
const;
273 [[nodiscard]] std::size_t
count( std::string_view T )
const;
279 template< std::contiguous_iterator I >
280 requires(
sizeof( std::iter_value_t< I > ) == 1 )
281 [[nodiscard]] std::pair< I , I >
operator()( I first , I last )
const {
282 const std::string_view T(
283 reinterpret_cast< const char *
>( std::to_address( first ) ) ,
284 std::size_t( last - first ) );
285 const std::size_t s =
find( T );
287 return( std::pair( last , last ) );
288 return( std::pair( first + std::ptrdiff_t( s ) ,
289 first + std::ptrdiff_t( s + f_P.size() ) ) );
293 [[nodiscard]] std::string_view
pattern(
void )
const {
return( f_P ); }
300 std::size_t scan( std::string_view T , std::size_t from , F && report )
const;
303 template<
int k ,
int W ,
class F >
304 std::size_t filter(
const unsigned char * T , std::size_t n ,
310 std::size_t filterBytes(
const unsigned char * T , std::size_t n ,
311 std::size_t from , F && report )
const;
316 std::size_t skip(
const unsigned char * T , std::size_t n , std::size_t from ,
323 std::size_t skipPair(
const unsigned char * T , std::size_t n ,
324 std::size_t from , F && report )
const;
327 [[nodiscard]] std::size_t gram(
const unsigned char * p )
const;
331 std::size_t
twoWay(
const unsigned char * T , std::size_t n ,
336 std::size_t f_off[ 4 ] = { 0 , 0 , 0 , 0 };
337 unsigned char f_byte[ 4 ] = { 0 , 0 , 0 , 0 };
340 std::uint64_t f_qmask = 0;
341 std::array< std::uint8_t , 4096 > f_shift;
342 std::size_t f_shift0 = 1;
351[[nodiscard]]
inline std::size_t
352findFirst( std::string_view T , std::string_view P , std::size_t from = 0 );
356[[nodiscard]]
inline std::vector< std::size_t >
findAll( std::string_view T ,
357 std::string_view P );
367#include "ADS/string/impl/StringSearch.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The prefetch of a line of the cache, beyond the book: ADS::prefetch( p ) asks the processor to bring ...
The vector kernels of ADS that are inlined in the middle of a search, on Google Highway,...
The exact string matching, beyond the book: the occurrences of a pattern of characters in a text o...
std::vector< std::size_t > findAll(std::string_view T) const
all the occurrences of in , in increasing order: the search of find(), which goes on after each occu...
std::size_t find(std::string_view T, std::size_t from=0) const
the first occurrence of at or after from in , npos if none
std::string_view pattern(void) const
the pattern
Definition StringSearch.h:293
StringSearcher(void)
the empty pattern
Definition StringSearch.h:194
static constexpr std::size_t npos
no place: the result of a search that finds no occurrence
Definition StringSearch.h:187
static constexpr std::size_t kSkip
the length from which a pattern is searched by the shifts of its q-grams instead of the filter of the...
Definition StringSearch.h:191
StringSearcher(std::string_view P)
the pattern prepared, its probes and the shifts of its q-grams, in
std::size_t count(std::string_view T) const
the number of occurrences of in , by the search of findAll()
std::vector< std::size_t > twoWay(std::string_view T, std::string_view P)
the places of all the occurrences of in , by the Two-Way algorithm of Crochemore and Perrin
std::size_t findFirst(std::string_view T, std::string_view P, std::size_t from=0)
the first occurrence of in at or after from, npos if none, by a StringSearcher used once
std::vector< std::size_t > findAll(std::string_view T, std::string_view P)
all the occurrences of in , overlapping ones included, by a StringSearcher used once