Program Listing for File MultiSearch.h
↰ Return to documentation for file (ADS/string/MultiSearch.h)
/*--------------------------------------------------------------------------*/
/*---------------------------- File MultiSearch.h --------------------------*/
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/*----------------------------- DEFINITIONS --------------------------------*/
/*--------------------------------------------------------------------------*/
#ifndef __ADS_MultiSearch
#define __ADS_MultiSearch
/* self-identification: #endif constant */
/*--------------------------------------------------------------------------*/
/*------------------------------ INCLUDES ----------------------------------*/
/*--------------------------------------------------------------------------*/
#include "ADS/Contract.h"
#include "ADS/string/AhoCorasick.h"
#include <array>
#include <cstddef>
#include <cstdint>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
/*--------------------------------------------------------------------------*/
/*--------------------------- NAMESPACE ------------------------------------*/
/*--------------------------------------------------------------------------*/
namespace ADS {
/*--------------------------------------------------------------------------*/
/*------------------------- CLASS MultiSearcher ----------------------------*/
/*--------------------------------------------------------------------------*/
class MultiSearcher {
/*--------------------------------------------------------------------------*/
public:
explicit MultiSearcher( const std::vector< std::string > & P );
[[nodiscard]] std::vector< std::pair< std::size_t , std::size_t > >
findAll( std::string_view T ) const;
[[nodiscard]] std::size_t count( std::string_view T ) const;
[[nodiscard]] std::size_t size( void ) const { return( f_P.size() ); }
[[nodiscard]] bool filtered( void ) const { return( f_q > 0 ); }
static constexpr std::size_t kFilter = 64;
/*--------------------------------------------------------------------------*/
private:
template< class F >
std::size_t scan( std::string_view T , F && report ) const;
static constexpr std::size_t npos = std::string_view::npos;
template< class F >
void automaton( std::string_view T , std::size_t from ,
F && report ) const;
template< class F >
std::size_t shiftOr( std::string_view T , F && report ) const;
template< class F >
std::size_t shiftOr2( std::string_view T , F && report ) const;
template< class F >
std::size_t verify( const unsigned char * T , std::size_t n ,
std::size_t s , F && report ) const;
template< class F >
std::size_t check( const unsigned char * T , std::size_t n , std::size_t s ,
std::uint64_t mask , const unsigned char * C ,
F && report ) const;
std::vector< std::string > f_P;
std::size_t f_q = 0;
std::size_t f_least = 0;
std::size_t f_longest = 0;
std::array< std::array< std::uint8_t , 16 > , 8 > f_lo{} , f_hi{};
std::array< std::vector< std::uint32_t > , 8 > f_bucket;
std::vector< std::uint64_t > f_head;
std::vector< std::uint64_t > f_mask;
std::size_t f_L = 0;
std::vector< std::uint64_t > f_sh;
std::size_t f_W = 0;
std::vector< std::uint64_t > f_sh2;
std::vector< std::uint32_t > f_first;
std::vector< std::uint32_t > f_next;
std::vector< std::uint64_t > f_key;
int f_bits = 0;
AhoCorasick f_ac;
}; // end( class MultiSearcher )
/*--------------------------------------------------------------------------*/
} // end( namespace ADS )
/*--------------------------------------------------------------------------*/
/*-------------------------- IMPLEMENTATION --------------------------------*/
/*--------------------------------------------------------------------------*/
#include "ADS/string/impl/MultiSearch.tpp"
/*--------------------------------------------------------------------------*/
#endif /* MultiSearch.h included */
/*--------------------------------------------------------------------------*/
/*------------------------- End File MultiSearch.h -------------------------*/
/*--------------------------------------------------------------------------*/