Skip to content
Snippets Groups Projects
Commit 29c38fb8 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

format code

parent 06be2ab9
No related branches found
No related tags found
No related merge requests found
...@@ -31,15 +31,16 @@ std::map < alphabet::RankedSymbol, size_t > ReversedBadCharacterShiftTable::bcs ...@@ -31,15 +31,16 @@ std::map < alphabet::RankedSymbol, size_t > ReversedBadCharacterShiftTable::bcs
bcs.insert ( std::make_pair ( symbol, pattern.getContent ( ).size ( ) ) ); bcs.insert ( std::make_pair ( symbol, pattern.getContent ( ).size ( ) ) );
} }
   
// find the distance between the beginning of the pattern and the index // find the distance between the beginning of the pattern and the index
// of the first symbol representing the variable's bar // of the first symbol representing the variable's bar
unsigned firstSBarOffset = pattern.getContent ( ).size ( ) + 1; unsigned firstSBarOffset = pattern.getContent ( ).size ( ) + 1;
for (int i = (int) pattern.getContent ( ).size ( ) - 1; i >= 0; i--) {
if ( pattern.getContent ( )[i].getSymbol() == pattern.getVariablesBarSymbol ( ) ) for ( int i = ( int ) pattern.getContent ( ).size ( ) - 1; i >= 0; i-- )
if ( pattern.getContent ( )[i].getSymbol ( ) == pattern.getVariablesBarSymbol ( ) )
firstSBarOffset = i; firstSBarOffset = i;
}
   
// limit the shift by occurrence of the last variable // limit the shift by occurrence of the last variable
for ( const alphabet::RankedSymbol & symbol : alphabet ) { for ( const alphabet::RankedSymbol & symbol : alphabet ) {
if ( ( symbol == pattern.getSubtreeWildcard ( ) ) || ( symbol.getSymbol ( ) == pattern.getVariablesBarSymbol ( ) ) ) continue; if ( ( symbol == pattern.getSubtreeWildcard ( ) ) || ( symbol.getSymbol ( ) == pattern.getVariablesBarSymbol ( ) ) ) continue;
   
...@@ -60,7 +61,7 @@ std::map < alphabet::RankedSymbol, size_t > ReversedBadCharacterShiftTable::bcs ...@@ -60,7 +61,7 @@ std::map < alphabet::RankedSymbol, size_t > ReversedBadCharacterShiftTable::bcs
} }
   
// limit the shift by position of symbols within the pattern // limit the shift by position of symbols within the pattern
for ( unsigned i = pattern.getContent ( ).size ( ) - 1; i >= 1 ; i-- ) // first symbol is not concerned for ( unsigned i = pattern.getContent ( ).size ( ) - 1; i >= 1; i-- ) // first symbol is not concerned
if ( ( pattern.getContent ( )[i] != pattern.getSubtreeWildcard ( ) ) && ( pattern.getContent ( )[i].getSymbol ( ) != pattern.getVariablesBarSymbol ( ) ) ) { if ( ( pattern.getContent ( )[i] != pattern.getSubtreeWildcard ( ) ) && ( pattern.getContent ( )[i].getSymbol ( ) != pattern.getVariablesBarSymbol ( ) ) ) {
size_t tmp = i; size_t tmp = i;
   
...@@ -85,17 +86,17 @@ std::map < alphabet::RankedSymbol, size_t > ReversedBadCharacterShiftTable::bcs ...@@ -85,17 +86,17 @@ std::map < alphabet::RankedSymbol, size_t > ReversedBadCharacterShiftTable::bcs
bcs.insert ( std::make_pair ( symbol, pattern.getContent ( ).size ( ) ) ); bcs.insert ( std::make_pair ( symbol, pattern.getContent ( ).size ( ) ) );
} }
   
// find the distance between the beginning of the pattern and the index // find the distance between the beginning of the pattern and the index
// of the first symbol representing the variable's bar // of the first symbol representing the variable's bar
unsigned firstSOffset = pattern.getContent ( ).size ( ) + 1; unsigned firstSOffset = pattern.getContent ( ).size ( ) + 1;
for (int i = (int) pattern.getContent ( ).size ( ) - 1; i >= 0; i--) {
for ( int i = ( int ) pattern.getContent ( ).size ( ) - 1; i >= 0; i-- )
if ( pattern.getContent ( )[i] == pattern.getSubtreeWildcard ( ) ) if ( pattern.getContent ( )[i] == pattern.getSubtreeWildcard ( ) )
firstSOffset = i; firstSOffset = i;
}
   
if(firstSOffset == 0) firstSOffset = 1; if ( firstSOffset == 0 ) firstSOffset = 1;
   
// limit the shift by occurrence of the last variable // limit the shift by occurrence of the last variable
for ( const alphabet::RankedSymbol & symbol : alphabet ) { for ( const alphabet::RankedSymbol & symbol : alphabet ) {
if ( symbol == pattern.getSubtreeWildcard ( ) ) continue; if ( symbol == pattern.getSubtreeWildcard ( ) ) continue;
   
...@@ -104,7 +105,7 @@ std::map < alphabet::RankedSymbol, size_t > ReversedBadCharacterShiftTable::bcs ...@@ -104,7 +105,7 @@ std::map < alphabet::RankedSymbol, size_t > ReversedBadCharacterShiftTable::bcs
} }
   
// limit the shift by position of symbols within the pattern // limit the shift by position of symbols within the pattern
for ( unsigned i = pattern.getContent ( ).size ( ) - 1; i >= 1 ; i-- ) // first symbol is not concerned for ( unsigned i = pattern.getContent ( ).size ( ) - 1; i >= 1; i-- ) // first symbol is not concerned
if ( pattern.getContent ( )[i] != pattern.getSubtreeWildcard ( ) ) { if ( pattern.getContent ( )[i] != pattern.getSubtreeWildcard ( ) ) {
size_t tmp = i; size_t tmp = i;
   
......
...@@ -35,11 +35,11 @@ auto ReversedBoyerMooreHorspoolPrefixRankedBarTreePrefixRankedBarTree = Reversed ...@@ -35,11 +35,11 @@ auto ReversedBoyerMooreHorspoolPrefixRankedBarTreePrefixRankedBarTree = Reversed
   
std::set < unsigned > ReversedBoyerMooreHorspool::match ( const tree::PrefixRankedBarTree & subject, const tree::PrefixRankedBarPattern & pattern ) { std::set < unsigned > ReversedBoyerMooreHorspool::match ( const tree::PrefixRankedBarTree & subject, const tree::PrefixRankedBarPattern & pattern ) {
std::set < unsigned > occ; std::set < unsigned > occ;
std::map < alphabet::RankedSymbol, size_t > bcs = ReversedBadCharacterShiftTable::bcs ( pattern ); //NOTE: the subjects alphabet must be a subset or equal to the pattern std::map < alphabet::RankedSymbol, size_t > bcs = ReversedBadCharacterShiftTable::bcs ( pattern ); // NOTE: the subjects alphabet must be a subset or equal to the pattern
std::vector < int > subjectSubtreeJumpTable = SubtreeJumpTable::compute ( subject ); std::vector < int > subjectSubtreeJumpTable = SubtreeJumpTable::compute ( subject );
   
// index to the subject // index to the subject
int i = (int) subject.getContent().size() - pattern.getContent().size() + 1; int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( ) + 1;
   
// main loop of the algorithm over all possible indexes where the pattern can start // main loop of the algorithm over all possible indexes where the pattern can start
while ( i >= 0 ) { while ( i >= 0 ) {
...@@ -50,7 +50,7 @@ std::set < unsigned > ReversedBoyerMooreHorspool::match ( const tree::PrefixRank ...@@ -50,7 +50,7 @@ std::set < unsigned > ReversedBoyerMooreHorspool::match ( const tree::PrefixRank
// offset to the subject // offset to the subject
unsigned offset = i; unsigned offset = i;
   
while ( ( j < pattern.getContent().size() ) && ( offset < subject.getContent().size() ) ) { while ( ( j < pattern.getContent ( ).size ( ) ) && ( offset < subject.getContent ( ).size ( ) ) ) {
if ( subject.getContent ( )[offset] == pattern.getContent ( )[j] ) { if ( subject.getContent ( )[offset] == pattern.getContent ( )[j] ) {
// match of symbol // match of symbol
offset = offset + 1; offset = offset + 1;
...@@ -65,7 +65,7 @@ std::set < unsigned > ReversedBoyerMooreHorspool::match ( const tree::PrefixRank ...@@ -65,7 +65,7 @@ std::set < unsigned > ReversedBoyerMooreHorspool::match ( const tree::PrefixRank
} }
   
// match was found // match was found
if ( j == pattern.getContent().size() ) occ.insert ( i ); if ( j == pattern.getContent ( ).size ( ) ) occ.insert ( i );
   
// shift heristics // shift heristics
i -= bcs[subject.getContent ( )[i]]; i -= bcs[subject.getContent ( )[i]];
...@@ -84,11 +84,11 @@ auto ReversedBoyerMooreHorspoolPrefixRankedBarTreePrefixRankedTree = ReversedBoy ...@@ -84,11 +84,11 @@ auto ReversedBoyerMooreHorspoolPrefixRankedBarTreePrefixRankedTree = ReversedBoy
   
std::set < unsigned > ReversedBoyerMooreHorspool::match ( const tree::PrefixRankedTree & subject, const tree::PrefixRankedPattern & pattern ) { std::set < unsigned > ReversedBoyerMooreHorspool::match ( const tree::PrefixRankedTree & subject, const tree::PrefixRankedPattern & pattern ) {
std::set < unsigned > occ; std::set < unsigned > occ;
std::map < alphabet::RankedSymbol, size_t > bcs = ReversedBadCharacterShiftTable::bcs ( pattern ); //NOTE: the subjects alphabet must be a subset or equal to the pattern std::map < alphabet::RankedSymbol, size_t > bcs = ReversedBadCharacterShiftTable::bcs ( pattern ); // NOTE: the subjects alphabet must be a subset or equal to the pattern
std::vector < int > subjectSubtreeJumpTable = SubtreeJumpTable::compute ( subject ); std::vector < int > subjectSubtreeJumpTable = SubtreeJumpTable::compute ( subject );
   
// index to the subject // index to the subject
int i = (int) subject.getContent().size() - pattern.getContent().size() + 1; int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( ) + 1;
   
// main loop of the algorithm over all possible indexes where the pattern can start // main loop of the algorithm over all possible indexes where the pattern can start
while ( i >= 0 ) { while ( i >= 0 ) {
...@@ -99,21 +99,21 @@ std::set < unsigned > ReversedBoyerMooreHorspool::match ( const tree::PrefixRank ...@@ -99,21 +99,21 @@ std::set < unsigned > ReversedBoyerMooreHorspool::match ( const tree::PrefixRank
// offset to the subject // offset to the subject
unsigned offset = i; unsigned offset = i;
   
while ( ( j < pattern.getContent().size() ) && ( offset < subject.getContent().size() ) ) { while ( ( j < pattern.getContent ( ).size ( ) ) && ( offset < subject.getContent ( ).size ( ) ) ) {
if ( subject.getContent ( )[offset] == pattern.getContent ( )[j] ) { if ( subject.getContent ( )[offset] == pattern.getContent ( )[j] )
// match of symbol // match of symbol
offset = offset + 1; offset = offset + 1;
} else if ( pattern.getContent ( )[j] == pattern.getSubtreeWildcard ( ) ) { else if ( pattern.getContent ( )[j] == pattern.getSubtreeWildcard ( ) )
// match of variable with subtree // match of variable with subtree
offset = subjectSubtreeJumpTable[offset]; offset = subjectSubtreeJumpTable[offset];
} else { else
break; break;
}
j = j + 1; j = j + 1;
} }
   
// match was found // match was found
if ( j == pattern.getContent().size() ) occ.insert ( i ); if ( j == pattern.getContent ( ).size ( ) ) occ.insert ( i );
   
// shift heristics // shift heristics
i -= bcs[subject.getContent ( )[i]]; i -= bcs[subject.getContent ( )[i]];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment