Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
BoyerMoore.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <alib/set>
9#include <alib/map>
10#include <alib/measure>
11
12#include <string/LinearString.h>
13
16
17#include <global/GlobalData.h>
18
19namespace stringology {
20
21namespace exact {
22
28public:
33 template < class SymbolType >
35
36};
37
38template < class SymbolType >
41
43 ext::map<SymbolType, size_t> bcs = string::properties::BadCharacterShiftTable::bcs(pattern); //NOTE: the subjects alphabet must be a subset or equal to the pattern
46
48 common::Streams::log << "bcs = " << bcs << std::endl;
49 common::Streams::log << "gss = " << gss << std::endl;
50 }
51
53 size_t haystack_offset = 0;
54 while(haystack_offset + pattern.getContent().size() <= string.getContent().size()) {
55 size_t i = pattern.getContent().size();
56 while(i > 0 && string.getContent()[haystack_offset + i - 1] == pattern.getContent()[i - 1]) {
57 i--;
58 }
59
60 // Yay, there is match!!!
61 if(i == 0) occ.insert(haystack_offset);
62 haystack_offset += std::max ( bcs[string.getContent()[haystack_offset + pattern.getContent().size() - 1]], gss [ pattern.getContent ( ).size ( ) - i ] );
63 //common::Streams::out << haystack_offset << std::endl;
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
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
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::vector< size_t > gss(const string::LinearString< SymbolType > &pattern)
Definition: GoodSuffixShiftTable.h:37
Definition: BoyerMoore.h:27
static ext::set< unsigned > match(const string::LinearString< SymbolType > &string, const string::LinearString< SymbolType > &pattern)
Definition: BoyerMoore.h:39
int i
Definition: AllEpsilonClosure.h:118
constexpr const T & max(const T &a)
Root case of maximum computation. The maximum from one value is the value itself.
Definition: algorithm.hpp:278
void start(measurements::stealth_string name, measurements::Type type)
Definition: measurements.cpp:14
void end()
Definition: measurements.cpp:19
Definition: ArithmeticCompression.h:18