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 <alib/set>
9#include <alib/map>
10
12
17
21
22namespace arbology {
23
24namespace exact {
25
32public:
37 template < class SymbolType >
39 template < class SymbolType >
41 template < class SymbolType >
43
44};
45
46template < class SymbolType >
48 return match ( subject, tree::PrefixRankedBarPattern < SymbolType > ( pattern ) );
49}
50
51template < class SymbolType >
54 ext::map < common::ranked_symbol < SymbolType >, size_t > bcs = tree::properties::QuickSearchBadCharacterShiftTable::bcs ( pattern ); // NOTE: the subjects alphabet must be a subset or equal to the pattern
55 ext::vector < int > subjectSubtreeJumpTable = tree::properties::SubtreeJumpTable::compute ( subject );
56
57 // index to the subject
58 unsigned i = pattern.getContent ( ).size ( ) - 1;
59
60 // main loop of the algorithm over all possible indexes where the pattern can start
61 while ( i < subject.getContent ( ).size ( ) ) {
62 // pair j and offset
63 ext::pair < int, int > jOffset = tree::exact::BackwardOccurrenceTest::occurrence ( subject, subjectSubtreeJumpTable, pattern, i );
64
65 // match was found
66 if ( jOffset.first == -1 ) occ.insert ( jOffset.second + 1);
67
68 if ( i + 1 >= subject.getContent ( ).size ( ) ) {
69 break;
70 }
71
72 // shift heuristics
73 i += bcs[subject.getContent ( )[i + 1]];
74 }
75
76 return occ;
77}
78
79template < class SymbolType >
82 ext::map < common::ranked_symbol < SymbolType >, size_t > bcs = tree::properties::QuickSearchBadCharacterShiftTable::bcs ( pattern ); //NOTE: the subjects alphabet must be a subset or equal to the pattern
83
84 ext::vector < int > subjectSubtreeJumpTable = tree::properties::SubtreeJumpTable::compute ( subject );
85 tree::PrefixRankedBarTree < unsigned > repeats = tree::properties::ExactSubtreeRepeatsNaive::repeats ( subject );
86
87 // index to the subject
88 unsigned i = pattern.getContent ( ).size ( ) - 1;
89
90 // main loop of the algorithm over all possible indexes where the pattern can start
91 while ( i < subject.getContent ( ).size ( ) ) {
92 // pair j and offset
93 ext::pair < int, int > jOffset = tree::exact::BackwardOccurrenceTest::occurrence ( subject, subjectSubtreeJumpTable, repeats, pattern, i );
94
95 // match was found
96 if ( jOffset.first == -1 ) occ.insert ( jOffset.second + 1);
97
98 if ( i + 1 >= subject.getContent ( ).size ( ) ) {
99 break;
100 }
101
102 // shift heuristics
103 i += bcs[subject.getContent ( )[i + 1]];
104 }
105
106 return occ;
107}
108
109} /* namespace exact */
110
111} /* namespace arbology */
112
Definition: QuickSearch.h:31
static ext::set< unsigned > match(const tree::PrefixRankedBarTree< SymbolType > &subject, const tree::PrefixRankedBarTree< SymbolType > &pattern)
Definition: QuickSearch.h:47
Class extending the map class from the standard library. Original reason is to allow printing of the ...
Definition: map.hpp:48
Class extending the pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
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
Nonlinear tree pattern represented as linear sequece as result of preorder traversal with additional ...
Definition: PrefixRankedBarNonlinearPattern.h:91
const ext::vector< common::ranked_symbol< SymbolType > > & getContent() const &
Definition: PrefixRankedBarNonlinearPattern.h:434
Tree pattern represented as linear sequece as result of preorder traversal with additional bar symbol...
Definition: PrefixRankedBarPattern.h:85
const ext::vector< common::ranked_symbol< SymbolType > > & getContent() const &
Definition: PrefixRankedBarPattern.h:334
Tree structure represented as linear sequece as result of preorder traversal with additional bar symb...
Definition: PrefixRankedBarTree.h:78
const ext::vector< common::ranked_symbol< SymbolType > > & getContent() const &
Definition: PrefixRankedBarTree.h:273
static ext::pair< int, int > occurrence(const PrefixRankedBarTree< SymbolType > &subject, const ext::vector< int > &subjectSubtreeJumpTable, const PrefixRankedBarTree< SymbolType > &pattern, size_t subjectPosition)
Definition: BackwardOccurrenceTest.h:33
static ext::map< common::ranked_symbol< SymbolType >, size_t > bcs(const tree::PrefixRankedBarPattern< SymbolType > &pattern)
Definition: QuickSearchBadCharacterShiftTable.h:33
static ext::vector< int > compute(const tree::PrefixRankedBarTree< SymbolType > &subject)
Definition: SubtreeJumpTable.h:49
Definition: BoyerMooreHorspool.h:22
int i
Definition: AllEpsilonClosure.h:118