Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
QuickSearch.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <set>
9#include <map>
10#include <alib/measure>
11
12#include <string/LinearString.h>
13
15
16#include <global/GlobalData.h>
17
18namespace stringology {
19
20namespace exact {
21
26public:
31 template < class SymbolType >
33
34};
35
36template < class SymbolType >
39
41 ext::map<SymbolType, size_t> bcs = string::properties::QuickSearchBadCharacterShiftTable::qsbcs(pattern); //NOTE: the subjects alphabet must be a subset or equal to the pattern
43
45 common::Streams::log << "bcs = " << bcs << std::endl;
46
48 size_t i = 0;
49 size_t j;
50 while( i + pattern.getContent().size() <= string.getContent().size() ) {
51 for ( j = 0; j < pattern.getContent().size(); j++ )
52 if ( pattern.getContent()[j] != string.getContent()[i+j])
53 break;
54
55 if ( j == pattern.getContent ( ).size ( ) ) {
56 occ.insert(i);
57 }
58
59 if ( i + pattern.getContent().size() == string.getContent().size() ) {
60 break; // Here we don't do any more shifts if the pattern is already aligned at the utter end of the text
61 }
62
63 i += bcs[string.getContent()[i+pattern.getContent().size()]];
64 }
66
67 return occ;
68}
69
70} /* namespace exact */
71
72} /* namespace stringology */
73
static bool verbose
Verbose flag. Some algorithms print additional runtime information about internal datastructures or t...
Definition: GlobalData.h:24
static ext::reference_wrapper< ext::ostream > log
Standard loging stream. Mapped to descriptor 4.
Definition: GlobalData.h:78
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 > qsbcs(const string::LinearString< SymbolType > &pattern)
Definition: QuickSearchBadCharacterShiftTable.h:32
Definition: QuickSearch.h:25
static ext::set< unsigned > match(const string::LinearString< SymbolType > &string, const string::LinearString< SymbolType > &pattern)
Definition: QuickSearch.h:37
int i
Definition: AllEpsilonClosure.h:118
void start(measurements::stealth_string name, measurements::Type type)
Definition: measurements.cpp:14
void end()
Definition: measurements.cpp:19
Definition: ArithmeticCompression.h:18