Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
DeadZoneUsingBadCharacterShift.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
15
16namespace stringology {
17
18namespace exact {
19
24 template < class SymbolType >
25 static void match_rec ( ext::set < unsigned > & occ, const string::LinearString < SymbolType > & string, const string::LinearString < SymbolType > & pattern, ext::map < SymbolType, size_t > & fbcs, ext::map < SymbolType, size_t > & bbcs, int low, int high );
26
27public:
32 template < class SymbolType >
34};
35
36template < class SymbolType >
39 ext::map < SymbolType, size_t > fbcs = string::properties::BadCharacterShiftTable::bcs ( pattern ); // NOTE: the subjects alphabet must be a subset or equal to the pattern
40 ext::map < SymbolType, size_t > bbcs = string::properties::ReversedBadCharacterShiftTable::bcs ( pattern ); // NOTE: the subjects alphabet must be a subset or equal to the pattern
41
42 match_rec ( occ, string, pattern, fbcs, bbcs, 0, string.getContent ( ).size ( ) - pattern.getContent ( ).size ( ) + 1 );
43 return occ;
44}
45
46template < class SymbolType >
47void DeadZoneUsingBadCharacterShift::match_rec ( ext::set < unsigned > & occ, const string::LinearString < SymbolType > & string, const string::LinearString < SymbolType > & pattern, ext::map < SymbolType, size_t > & fbcs, ext::map < SymbolType, size_t > & bbcs, int low, int high ) {
48 if ( low >= high ) return;
49
50 int middle = ( low + high ) / 2;
51 size_t i = 0;
52
53 while ( i < pattern.getContent ( ).size ( ) && string.getContent ( )[middle + i] == pattern.getContent ( )[i] )
54 i++;
55
56 // Yay, there is match!!!
57 if ( i == pattern.getContent ( ).size ( ) ) occ.insert ( middle );
58
59 match_rec ( occ, string, pattern, fbcs, bbcs, low, middle - bbcs[string.getContent ( )[middle]] + 1 );
60 match_rec ( occ, string, pattern, fbcs, bbcs, middle + fbcs[string.getContent ( )[middle + pattern.getContent ( ).size ( ) - 1]], high );
61}
62
63} /* namespace exact */
64
65} /* namespace stringology */
66
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: BadCharacterShiftTable.h:33
static ext::map< SymbolType, size_t > bcs(const string::LinearString< SymbolType > &pattern)
Definition: ReversedBadCharacterShiftTable.h:33
Definition: DeadZoneUsingBadCharacterShift.h:23
static ext::set< unsigned > match(const string::LinearString< SymbolType > &string, const string::LinearString< SymbolType > &pattern)
Definition: DeadZoneUsingBadCharacterShift.h:37
int i
Definition: AllEpsilonClosure.h:118
Definition: ArithmeticCompression.h:18