Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Concepts
CompressedBitParallelismPatterns.h
Go to the documentation of this file.
1
6#pragma once
7
11#include <global/GlobalData.h>
12
13namespace arbology {
14
15namespace query {
16
23
24public:
31 template < class SymbolType >
33
34 template < class SymbolType >
36};
37
38template < class SymbolType >
40 auto symbolIter = pattern.getContent ( ).begin ( );
41
42 if ( pattern.getSubtreeWildcard ( ) == * symbolIter ) {
44
45 for ( size_t i = 0; i < compressedBitParallelIndex.getJumps ( ).size ( ); ++ i )
46 res.insert ( i );
47
48 return res;
49 }
50
51 typename ext::map < common::ranked_symbol < SymbolType >, common::SparseBoolVector >::const_iterator symbolVectorIter = compressedBitParallelIndex.getData ( ).find ( * symbolIter );
52
53 if ( symbolVectorIter == compressedBitParallelIndex.getData ( ).end ( ) )
54 return { };
55
56 common::SparseBoolVector indexVector = symbolVectorIter->second;
57
58 for ( ++ symbolIter; symbolIter != pattern.getContent ( ).end ( ); ++ symbolIter ) {
59 if ( * symbolIter == pattern.getSubtreeWildcard ( ) ) {
61 newVector.resize ( indexVector.size ( ) );
62
63 for ( unsigned i : ( indexVector << 1 ) )
64 newVector [ compressedBitParallelIndex.getJumps ( ) [ i ] - 1 ] = true;
65
66 indexVector = newVector;
67 } else {
68 symbolVectorIter = compressedBitParallelIndex.getData ( ).find ( * symbolIter );
69
70 if ( symbolVectorIter == compressedBitParallelIndex.getData ( ).end ( ) )
71 return { };
72
73 indexVector = ( indexVector << 1 ) & symbolVectorIter->second;
74 }
75 }
76
78
79 for ( unsigned i : indexVector )
80 res.insert ( i + 1 );
81
82 return res;
83}
84
85template < class SymbolType >
87 auto symbolIter = pattern.getContent ( ).begin ( );
88
89 if ( pattern.getSubtreeWildcard ( ) == * symbolIter ) {
91
92 for ( size_t i = 0; i < compressedBitParallelIndex.getJumps ( ).size ( ) - 1; ++ i ) //last index maps to -1
93 if ( static_cast < size_t > ( compressedBitParallelIndex.getJumps ( ) [ i ] ) > i )
94 res.insert ( i );
95
96 return res;
97 }
98
99 typename ext::map < common::ranked_symbol < SymbolType >, common::SparseBoolVector >::const_iterator symbolVectorIter = compressedBitParallelIndex.getData ( ).find ( * symbolIter );
100
101 if ( symbolVectorIter == compressedBitParallelIndex.getData ( ).end ( ) )
102 return { };
103
104 common::SparseBoolVector indexVector = symbolVectorIter->second;
105
106 for ( ++ symbolIter; symbolIter != pattern.getContent ( ).end ( ); ++ symbolIter ) {
107 if ( * symbolIter == pattern.getSubtreeWildcard ( ) ) {
108 common::SparseBoolVector newVector;
109 newVector.resize ( indexVector.size ( ) );
110
111 for ( unsigned i : ( indexVector << 1 ) )
112 newVector [ compressedBitParallelIndex.getJumps ( ) [ i ] - 1 ] = true;
113
114 indexVector = newVector;
115
116 ++ symbolIter;
117 } else {
118 symbolVectorIter = compressedBitParallelIndex.getData ( ).find ( * symbolIter );
119
120 if ( symbolVectorIter == compressedBitParallelIndex.getData ( ).end ( ) )
121 return { };
122
123 indexVector = ( indexVector << 1 ) & symbolVectorIter->second;
124 }
125 }
126
128
129 for ( unsigned i : indexVector )
130 res.insert ( i + 1 );
131
132 return res;
133}
134
135} /* namespace query */
136
137} /* namespace arbology */
138
Definition: CompressedBitParallelismPatterns.h:22
static ext::set< unsigned > query(const indexes::arbology::CompressedBitParallelTreeIndex< SymbolType > &compressedBitParallelIndex, const tree::PrefixRankedPattern< SymbolType > &pattern)
Definition: CompressedBitParallelismPatterns.h:39
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
Definition: set.hpp:44
Compressed bit parallel tree index. Stores a bit vector for each symbol of the alphabet....
Definition: CompressedBitParallelTreeIndex.h:55
const ext::map< common::ranked_symbol< SymbolType >, common::SparseBoolVector > & getData() const &
Definition: CompressedBitParallelTreeIndex.h:194
const ext::vector< int > & getJumps() const &
Definition: CompressedBitParallelTreeIndex.h:204
Tree pattern represented as linear sequece as result of preorder traversal with additional bar symbol...
Definition: PrefixRankedBarPattern.h:85
const common::ranked_symbol< SymbolType > & getSubtreeWildcard() const &
Definition: PrefixRankedBarPattern.h:202
const ext::vector< common::ranked_symbol< SymbolType > > & getContent() const &
Definition: PrefixRankedBarPattern.h:334
Tree pattern represented as linear sequece as result of preorder traversal. The representation is so ...
Definition: PrefixRankedPattern.h:77
const ext::vector< common::ranked_symbol< SymbolType > > & getContent() const &
Definition: PrefixRankedPattern.h:262
const common::ranked_symbol< SymbolType > & getSubtreeWildcard() const &
Definition: PrefixRankedPattern.h:154
Definition: BoyerMooreHorspool.h:22
int i
Definition: AllEpsilonClosure.h:118
return res
Definition: MinimizeByPartitioning.h:145
void end()
Definition: measurements.cpp:19