Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
ReversedBoyerMooreHorspool.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <alib/set>
9#include <alib/map>
10
11#include <string/LinearString.h>
12
14
15namespace stringology {
16
17namespace exact {
18
24public:
29 template < class SymbolType >
31
32};
33
34template < class SymbolType >
37 ext::map < SymbolType, size_t > bcs = string::properties::ReversedBadCharacterShiftTable::bcs ( pattern ); // NOTE: the subjects alphabet must be a subset or equal to the pattern
38
39 if ( string.getContent ( ).size ( ) < pattern.getContent ( ).size ( ) )
40 return occ;
41
42 // index to the subject
43 size_t i = string.getContent ( ).size ( ) - pattern.getContent ( ).size ( );
44
45 // main loop of the algorithm over all possible indexes where the pattern can start
46 while ( true ) {
47 size_t j = 0;
48
49 while ( j < pattern.getContent ( ).size ( ) && string.getContent ( ) [ i + j ] == pattern.getContent ( ) [ j ] )
50 j++;
51
52 // Yay, there is match!!!
53 if ( j == pattern.getContent ( ).size ( ) ) occ.insert ( i );
54
55 // shift heristics
56 size_t shift = bcs [ string.getContent ( ) [ i ] ];
57
58 if ( shift > i )
59 break;
60
61 i -= shift;
62
63 // common::Streams::out << haystack_offset << std::endl;
64 }
65
66 return occ;
67}
68
69} /* namespace exact */
70
71} /* namespace stringology */
72
Class extending the map class from the standard library. Original reason is to allow printing of the ...
Definition: map.hpp:48
Definition: set.hpp:44
Linear string.
Definition: LinearString.h:57
const ext::vector< SymbolType > & getContent() const &
Definition: LinearString.h:238
static ext::map< SymbolType, size_t > bcs(const string::LinearString< SymbolType > &pattern)
Definition: ReversedBadCharacterShiftTable.h:33
Definition: ReversedBoyerMooreHorspool.h:23
static ext::set< unsigned > match(const string::LinearString< SymbolType > &string, const string::LinearString< SymbolType > &pattern)
Definition: ReversedBoyerMooreHorspool.h:35
int i
Definition: AllEpsilonClosure.h:118
Definition: ArithmeticCompression.h:18