Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
BoyerMooreHorspool.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
15
16#include <global/GlobalData.h>
17
18namespace stringology {
19
20namespace exact {
21
27public:
32 template < class SymbolType >
34
35};
36
37template < class SymbolType >
40
42 ext::map<SymbolType, size_t> bcs = string::properties::BadCharacterShiftTable::bcs(pattern); //NOTE: the subjects alphabet must be a subset or equal to the pattern
44
46 common::Streams::log << "bcs = " << bcs << std::endl;
47
49 size_t haystack_offset = 0;
50 while(haystack_offset + pattern.getContent().size() <= string.getContent().size()) {
51 size_t i = pattern.getContent().size();
52 while(i > 0 && string.getContent()[haystack_offset + i - 1] == pattern.getContent()[i - 1]) {
53 i--;
54 }
55
56 // Yay, there is match!!!
57 if(i == 0) occ.insert(haystack_offset);
58 haystack_offset += bcs[string.getContent()[haystack_offset + pattern.getContent().size() - 1]];
59 //common::Streams::out << haystack_offset << std::endl;
60 }
62
63 return occ;
64}
65
66} /* namespace exact */
67
68} /* namespace stringology */
69
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 > bcs(const string::LinearString< SymbolType > &pattern)
Definition: BadCharacterShiftTable.h:33
Definition: BoyerMooreHorspool.h:26
static ext::set< unsigned > match(const string::LinearString< SymbolType > &string, const string::LinearString< SymbolType > &pattern)
Definition: BoyerMooreHorspool.h:38
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