ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
MultiSearch.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*---------------------------- File MultiSearch.h --------------------------*/
3/*--------------------------------------------------------------------------*/
123/*--------------------------------------------------------------------------*/
124/*----------------------------- DEFINITIONS --------------------------------*/
125/*--------------------------------------------------------------------------*/
126
127#ifndef __ADS_MultiSearch
128 #define __ADS_MultiSearch
129/* self-identification: #endif constant */
130
131/*--------------------------------------------------------------------------*/
132/*------------------------------ INCLUDES ----------------------------------*/
133/*--------------------------------------------------------------------------*/
134
135#include "ADS/Contract.h"
137
138#include <array>
139#include <cstddef>
140#include <cstdint>
141#include <string>
142#include <string_view>
143#include <utility>
144#include <vector>
145
146/*--------------------------------------------------------------------------*/
147/*--------------------------- NAMESPACE ------------------------------------*/
148/*--------------------------------------------------------------------------*/
149
150namespace ADS
151{
152
153/*--------------------------------------------------------------------------*/
154/*------------------------- CLASS MultiSearcher ----------------------------*/
155/*--------------------------------------------------------------------------*/
156
160{
161
162/*--------------------------------------------------------------------------*/
163 public:
199 explicit MultiSearcher( const std::vector< std::string > & P );
200
232 [[nodiscard]] std::vector< std::pair< std::size_t , std::size_t > >
233 findAll( std::string_view T ) const;
234
237 [[nodiscard]] std::size_t count( std::string_view T ) const;
238
242 [[nodiscard]] std::size_t automatonFrom( std::string_view T ) const;
243
245 [[nodiscard]] std::size_t size( void ) const { return( f_P.size() ); }
246
248 [[nodiscard]] bool filtered( void ) const { return( f_q > 0 ); }
249
252 static constexpr std::size_t kFilter = 64;
253
254/*--------------------------------------------------------------------------*/
255 private:
259 template< class F >
260 std::size_t scan( std::string_view T , F && report ) const;
261
263 static constexpr std::size_t npos = std::string_view::npos;
264
267 template< class F >
268 void automaton( std::string_view T , std::size_t from , F && report ) const;
269
271 template< class F >
272 std::size_t shiftOr( std::string_view T , F && report ) const;
273
275 template< class F >
276 std::size_t shiftOr2( std::string_view T , F && report ) const;
277
280 template< class F >
281 std::size_t verify( const unsigned char * T , std::size_t n , std::size_t s ,
282 F && report ) const;
283
287 template< class F >
288 std::size_t check( const unsigned char * T , std::size_t n , std::size_t s ,
289 std::uint64_t mask , const unsigned char * C ,
290 F && report ) const;
291
292 std::vector< std::string > f_P;
293 std::size_t f_q = 0;
294 std::size_t f_least = 0;
295 std::size_t f_longest = 0;
297 std::array< std::array< std::uint8_t , 16 > , 8 > f_lo{} , f_hi{};
298 std::array< std::vector< std::uint32_t > , 8 > f_bucket;
299 std::vector< std::uint64_t > f_head;
300 std::vector< std::uint64_t > f_mask;
301 std::size_t f_L = 0;
302 std::vector< std::uint64_t > f_sh;
303 std::size_t f_W = 0;
304 std::vector< std::uint64_t > f_sh2;
305 std::vector< std::uint32_t > f_first;
306 std::vector< std::uint32_t > f_next;
307 std::vector< std::uint64_t > f_key;
308 int f_bits = 0;
309 AhoCorasick f_ac;
310
311 }; // end( class MultiSearcher )
312
313/*--------------------------------------------------------------------------*/
314
315} // end( namespace ADS )
316
317/*--------------------------------------------------------------------------*/
318/*-------------------------- IMPLEMENTATION --------------------------------*/
319/*--------------------------------------------------------------------------*/
320
321#include "ADS/string/impl/MultiSearch.tpp"
322
323/*--------------------------------------------------------------------------*/
324
325#endif /* MultiSearch.h included */
326
327/*--------------------------------------------------------------------------*/
328/*------------------------- End File MultiSearch.h -------------------------*/
329/*--------------------------------------------------------------------------*/
The search of many patterns at once, beyond the book: the automaton of Aho and Corasick of a set of p...
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
bool filtered(void) const
whether the filter of shuffles searches (else the shift-or filter)
Definition MultiSearch.h:248
static constexpr std::size_t kFilter
the most patterns of the filter of shuffles, beyond which the shift-or filter searches
Definition MultiSearch.h:252
std::vector< std::pair< std::size_t, std::size_t > > findAll(std::string_view T) const
the occurrences of the patterns in , by increasing start and number
MultiSearcher(const std::vector< std::string > &P)
the patterns , numbered in their order, and the filter that suits them
std::size_t size(void) const
the number of patterns
Definition MultiSearch.h:245
std::size_t automatonFrom(std::string_view T) const
the place of from which the automaton takes over the search of findAll() and count(),...
std::size_t count(std::string_view T) const
the number of the occurrences of the patterns in , by the search of findAll()
Definition ADT.h:96