Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
QuickSearchBadCharacterShiftTable.h
Go to the documentation of this file.
1
6#pragma once
7
10
12
13#include <alib/set>
14#include <alib/map>
15
16namespace tree {
17
18namespace properties {
19
24public:
25 template < class SymbolType >
27 template < class SymbolType >
29
30};
31
32template < class SymbolType >
35}
36
37template < class SymbolType >
40
42
43 // initialisation of bcs table to the size of the pattern plus one
44 for ( const common::ranked_symbol < SymbolType > & symbol : alphabet ) {
45 if ( symbol == pattern.getSubtreeWildcard ( ) || pattern.getNonlinearVariables ( ).count ( symbol ) || symbol == pattern.getVariablesBar ( ) )
46 continue;
47
48 bcs.insert ( std::make_pair ( symbol, pattern.getContent ( ).size ( ) + 1 ) );
49 }
50
51 // find the distance between the end of the pattern and the index
52 // of the last symbol representing the variable
53 size_t lastSOffset = LastVariableOffsetBack::offset ( pattern );
54
55 // limit the shift by occurrence of the last variable
56
57 for ( const common::ranked_symbol < SymbolType > & symbol : alphabet ) {
58 if ( symbol == pattern.getSubtreeWildcard ( ) || pattern.getNonlinearVariables ( ).count ( symbol ) || symbol == pattern.getVariablesBar ( ) )
59 continue;
60
61 size_t tmp = lastSOffset + 1;
62
63 if ( ! pattern.getBars ( ).count ( symbol ) )
64 // size of the smallest subtree containing given terminal depend
65 // on the arity of the terminal
66 tmp += symbol.getRank ( ) * 2;
67 else
68 // bar symbols match the variable bar which is one symbol after
69 // the last variable, conditioned because of the case S S| where
70 // the -1 would cause shift by 0 -- illegal
71 tmp -= 1;
72
73 if ( bcs[symbol] > tmp )
74 bcs[symbol] = tmp;
75 }
76
77 // limit the shift by position of symbols within the pattern
78 for ( unsigned i = 0; i < pattern.getContent ( ).size ( ); i++ ) {
79 if ( pattern.getContent ( )[i] == pattern.getSubtreeWildcard ( ) || pattern.getNonlinearVariables ( ).count ( pattern.getContent ( )[i] ) || pattern.getContent ( )[i] == pattern.getVariablesBar ( ) )
80 continue;
81
82 size_t tmp = pattern.getContent ( ).size ( ) - i;
83
84 if ( bcs[pattern.getContent ( )[i]] > tmp )
85 bcs[pattern.getContent ( )[i]] = tmp;
86 }
87
88 return bcs;
89}
90
91} /* namespace properties */
92
93} /* namespace tree */
94
Definition: ranked_symbol.hpp:20
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
Nonlinear tree pattern represented as linear sequece as result of preorder traversal with additional ...
Definition: PrefixRankedBarNonlinearPattern.h:91
const ext::set< common::ranked_symbol< SymbolType > > & getBars() const &
Definition: PrefixRankedBarNonlinearPattern.h:232
const ext::set< common::ranked_symbol< SymbolType > > & getNonlinearVariables() const &
Definition: PrefixRankedBarNonlinearPattern.h:277
const common::ranked_symbol< SymbolType > & getSubtreeWildcard() const &
Definition: PrefixRankedBarNonlinearPattern.h:259
const ext::set< common::ranked_symbol< SymbolType > > & getAlphabet() const &
Definition: PrefixRankedBarNonlinearPattern.h:205
const ext::vector< common::ranked_symbol< SymbolType > > & getContent() const &
Definition: PrefixRankedBarNonlinearPattern.h:434
const common::ranked_symbol< SymbolType > & getVariablesBar() const &
Definition: PrefixRankedBarNonlinearPattern.h:295
Tree pattern represented as linear sequece as result of preorder traversal with additional bar symbol...
Definition: PrefixRankedBarPattern.h:85
static size_t offset(const tree::PrefixRankedBarPattern< SymbolType > &pattern)
Definition: LastVariableOffsetBack.h:25
Definition: QuickSearchBadCharacterShiftTable.h:23
static ext::map< common::ranked_symbol< SymbolType >, size_t > bcs(const tree::PrefixRankedBarPattern< SymbolType > &pattern)
Definition: QuickSearchBadCharacterShiftTable.h:33
Definition: BarSymbol.cpp:12
int i
Definition: AllEpsilonClosure.h:118
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79
Definition: BackwardOccurrenceTest.h:17