Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
BadCharacterShiftTable.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
25public:
26 template < class SymbolType >
28 template < class SymbolType >
30
31};
32
33template < class SymbolType >
36}
37
38template < class SymbolType >
41
43
44 // initialisation of bcs table to the size of the pattern
45 for ( const common::ranked_symbol < SymbolType > & symbol : alphabet ) {
46 if ( symbol == pattern.getSubtreeWildcard ( ) || pattern.getNonlinearVariables ( ).count ( symbol ) || symbol == pattern.getVariablesBar ( ) )
47 continue;
48
49 bcs.insert ( std::make_pair ( symbol, pattern.getContent ( ).size ( ) ) );
50 }
51
52 // find the distance between the end of the pattern and the index
53 // of the last symbol representing the variable
54 size_t lastSOffset = LastVariableOffsetBack::offset ( pattern );
55
56 // limit the shift by occurrence of the last variable
57
58 for ( const common::ranked_symbol < SymbolType > & symbol : alphabet ) {
59 if ( symbol == pattern.getSubtreeWildcard ( ) || pattern.getNonlinearVariables ( ).count ( symbol ) || symbol == pattern.getVariablesBar ( ) )
60 continue;
61
62 size_t tmp = lastSOffset;
63
64 if ( ! pattern.getBars ( ).count ( symbol ) )
65 // size of the smallest subtree containing given terminal depend
66 // on the arity of the terminal
67 tmp += symbol.getRank ( ) * 2;
68 else if ( tmp >= 2 )
69 // bar symbols match the variable bar which is one symbol after
70 // the last variable, conditioned because of the case S S| where
71 // the -1 would cause shift by 0 -- illegal
72 tmp -= 1;
73
74 if ( bcs[symbol] > tmp )
75 bcs[symbol] = tmp;
76 }
77
78 // limit the shift by position of symbols within the pattern
79 for ( size_t i = 0; i < pattern.getContent ( ).size ( ) - 1; i++ ) { // last symbol is not concerned
80 if ( pattern.getContent ( )[i] == pattern.getSubtreeWildcard ( ) || pattern.getNonlinearVariables ( ).count ( pattern.getContent ( )[i] ) || pattern.getContent ( )[i] == pattern.getVariablesBar ( ) )
81 continue;
82
83 size_t tmp = pattern.getContent ( ).size ( ) - i - 1;
84
85 if ( bcs[pattern.getContent ( )[i]] > tmp )
86 bcs[pattern.getContent ( )[i]] = tmp;
87 }
88
89 return bcs;
90}
91
92} /* namespace properties */
93
94} /* namespace tree */
95
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
Definition: BadCharacterShiftTable.h:24
static ext::map< common::ranked_symbol< SymbolType >, size_t > bcs(const tree::PrefixRankedBarPattern< SymbolType > &pattern)
Definition: BadCharacterShiftTable.h:34
static size_t offset(const tree::PrefixRankedBarPattern< SymbolType > &pattern)
Definition: LastVariableOffsetBack.h:25
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