Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
NonlinearCompressedBitParallelismPatterns.h
Go to the documentation of this file.
1
6#pragma once
7
10#include <global/GlobalData.h>
11
12namespace arbology {
13
14namespace query {
15
22
23public:
30 template < class SymbolType >
32};
33
34template < class SymbolType >
35bool include ( unsigned i, const ext::vector < unsigned > & repeats, const ext::vector < int > & jumps, const tree::PrefixRankedBarNonlinearPattern < SymbolType > & pattern ) {
36 ext::map < common::ranked_symbol < SymbolType >, unsigned > variablesSetting;
37
38 // index to the pattern
39 int j = pattern.getContent ( ).size ( ) - 1;
40
41 while ( j >= 0 ) {
42 if ( pattern.getContent ( )[j] == pattern.getVariablesBar ( ) ) {
43 i = jumps[i];
44 j = j - 2;
45
46 // check nonlinear variable
47 if ( pattern.getNonlinearVariables ( ).count ( pattern.getContent ( )[ j + 1 ] ) ) {
48 auto setting = variablesSetting.find ( pattern.getContent ( )[ j + 1 ] );
49
50 if ( setting != variablesSetting.end ( ) && repeats [ i + 1 ] != setting->second )
51 break;
52
53 variablesSetting.insert ( std::make_pair ( pattern.getContent ( )[ j + 1 ], repeats [ i + 1 ] ) );
54 }
55 } else {
56 // match of symbol
57 i = i - 1;
58 j = j - 1;
59 }
60 }
61
62 return j == -1;
63
64}
65
66template < class SymbolType >
68 auto symbolIter = pattern.getContent ( ).begin ( );
69
70 if ( pattern.getSubtreeWildcard ( ) == * symbolIter || pattern.getNonlinearVariables ( ).count ( * symbolIter ) ) {
72
73 for ( size_t i = 0; i < nonlinearCompressedBitParallelIndex.getJumps ( ).size ( ) - 1; ++ i ) //last index maps to -1
74 if ( static_cast < size_t > ( nonlinearCompressedBitParallelIndex.getJumps ( ) [ i ] ) > i )
75 res.insert ( i );
76
77 return res;
78 }
79
80 typename ext::map < common::ranked_symbol < SymbolType >, common::SparseBoolVector >::const_iterator symbolVectorIter = nonlinearCompressedBitParallelIndex.getData ( ).find ( * symbolIter );
81
82 if ( symbolVectorIter == nonlinearCompressedBitParallelIndex.getData ( ).end ( ) )
83 return { };
84
85 common::SparseBoolVector indexVector = symbolVectorIter->second;
86
87 for ( ++ symbolIter; symbolIter != pattern.getContent ( ).end ( ); ++ symbolIter ) {
88 if ( * symbolIter == pattern.getSubtreeWildcard ( ) || pattern.getNonlinearVariables ( ).count ( * symbolIter ) ) {
90 newVector.resize ( indexVector.size ( ) );
91
92 for ( unsigned i : ( indexVector << 1 ) )
93 newVector [ nonlinearCompressedBitParallelIndex.getJumps ( ) [ i ] - 1 ] = true;
94
95 indexVector = newVector;
96
97 ++ symbolIter;
98 } else {
99 symbolVectorIter = nonlinearCompressedBitParallelIndex.getData ( ).find ( * symbolIter );
100
101 if ( symbolVectorIter == nonlinearCompressedBitParallelIndex.getData ( ).end ( ) )
102 return { };
103
104 indexVector = ( indexVector << 1 ) & symbolVectorIter->second;
105 }
106 }
107
109
110 for ( unsigned i : indexVector )
111 if ( include ( i, nonlinearCompressedBitParallelIndex.getRepeats ( ), nonlinearCompressedBitParallelIndex.getJumps ( ), pattern ) )
112 res.insert ( i + 1 );
113
114 return res;
115}
116
117} /* namespace query */
118
119} /* namespace arbology */
120
Definition: NonlinearCompressedBitParallelismPatterns.h:21
static ext::set< unsigned > query(const indexes::arbology::NonlinearCompressedBitParallelTreeIndex< SymbolType > &nonlinearCompressedBitParallelIndex, const tree::PrefixRankedBarNonlinearPattern< SymbolType > &pattern)
Definition: NonlinearCompressedBitParallelismPatterns.h:67
Definition: SparseBoolVector.hpp:27
size_t size() const
Definition: SparseBoolVector.hpp:223
void resize(size_t newSize)
Definition: SparseBoolVector.hpp:212
Class extending the map class from the standard library. Original reason is to allow printing of the ...
Definition: map.hpp:48
std::pair< iterator, bool > insert(const T &key, const R &value)
Insert variant with explicit key and value parameters.
Definition: map.hpp:118
auto end() &
Inherited behavior of end for non-const instance.
Definition: map.hpp:215
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
Compressed bit parallel nonlinear tree index. Stores a bit vector for each symbol of the alphabet....
Definition: NonlinearCompressedBitParallelTreeIndex.h:55
const ext::vector< int > & getJumps() const &
Definition: NonlinearCompressedBitParallelTreeIndex.h:224
const ext::map< common::ranked_symbol< SymbolType >, common::SparseBoolVector > & getData() const &
Definition: NonlinearCompressedBitParallelTreeIndex.h:214
const ext::vector< unsigned > & getRepeats() const &
Definition: NonlinearCompressedBitParallelTreeIndex.h:234
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 > > & getNonlinearVariables() const &
Definition: PrefixRankedBarNonlinearPattern.h:277
const common::ranked_symbol< SymbolType > & getSubtreeWildcard() const &
Definition: PrefixRankedBarNonlinearPattern.h:259
const ext::vector< common::ranked_symbol< SymbolType > > & getContent() const &
Definition: PrefixRankedBarNonlinearPattern.h:434
const common::ranked_symbol< SymbolType > & getVariablesBar() const &
Definition: PrefixRankedBarNonlinearPattern.h:295
bool include(unsigned i, const ext::vector< unsigned > &repeats, const ext::vector< int > &jumps, const tree::PrefixRankedBarNonlinearPattern< SymbolType > &pattern)
Definition: NonlinearCompressedBitParallelismPatterns.h:35
Definition: BoyerMooreHorspool.h:22
int i
Definition: AllEpsilonClosure.h:118
return res
Definition: MinimizeByPartitioning.h:145
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79
void end()
Definition: measurements.cpp:19