From 30acc96009585a9838cb6c15a5ac651a20ca34e8 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Fri, 22 Jul 2016 13:50:46 +0200 Subject: [PATCH] fix implementation of bmh for trees --- .../src/arbology/exact/BoyerMooreHorspool.cpp | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/alib2algo/src/arbology/exact/BoyerMooreHorspool.cpp b/alib2algo/src/arbology/exact/BoyerMooreHorspool.cpp index 4c3b3058f4..21f8c3a328 100644 --- a/alib2algo/src/arbology/exact/BoyerMooreHorspool.cpp +++ b/alib2algo/src/arbology/exact/BoyerMooreHorspool.cpp @@ -44,12 +44,12 @@ std::set < unsigned > BoyerMooreHorspool::match ( const tree::PrefixRankedBarTre while ( i + pattern.getContent ( ).size ( ) <= subject.getContent ( ).size ( ) ) { // index to the pattern - unsigned j = pattern.getContent ( ).size ( ) - 1; + int j = pattern.getContent ( ).size ( ) - 1; // offset to the subject - unsigned offset = i + j; + int offset = i + j; - while ( ( j > 0 ) && ( offset > 0 ) ) { + while ( ( j >= 0 ) && ( offset >= 0 ) ) { if ( subject.getContent ( )[offset] == pattern.getContent ( )[j] ) { // match of symbol offset = offset - 1; @@ -64,7 +64,7 @@ std::set < unsigned > BoyerMooreHorspool::match ( const tree::PrefixRankedBarTre } // match was found - if ( j == 0 ) occ.insert ( offset ); + if ( j == -1 ) occ.insert ( offset ); // shift heuristics i += bcs[subject.getContent ( )[i + pattern.getContent ( ).size ( ) - 1]]; @@ -92,12 +92,12 @@ std::set < unsigned > BoyerMooreHorspool::match ( const tree::PrefixRankedBarTre variablesSetting.clear(); // index to the pattern - unsigned j = pattern.getContent ( ).size ( ) - 1; + int j = pattern.getContent ( ).size ( ) - 1; // offset to the subject - unsigned offset = i + j; + int offset = i + j; - while ( ( j > 0 ) && ( offset > 0 ) ) { + while ( ( j >= 0 ) && ( offset >= 0 ) ) { if ( subject.getContent ( )[offset] == pattern.getContent ( )[j] ) { // match of symbol offset = offset - 1; @@ -105,24 +105,24 @@ std::set < unsigned > BoyerMooreHorspool::match ( const tree::PrefixRankedBarTre } else if ( ( pattern.getContent ( )[j] == pattern.getVariablesBar ( ) ) && ( pattern.getBars ( ).count ( subject.getContent ( )[offset] )) ) { // else match of variable with subtree offset = subjectSubtreeJumpTable[offset]; + j = j - 2; // check nonlinear variable - if ( pattern.getNonlinearVariables ( ).count ( pattern.getContent ( )[ j - 1 ] ) ) { - auto setting = variablesSetting.find ( pattern.getContent ( )[ j - 1 ] ); + if ( pattern.getNonlinearVariables ( ).count ( pattern.getContent ( )[ j + 1 ] ) ) { + auto setting = variablesSetting.find ( pattern.getContent ( )[ j + 1 ] ); if ( setting != variablesSetting.end ( ) && repeats.getContent ( )[ offset + 1 ].getSymbol ( ) != setting->second ) break; - variablesSetting.insert ( std::make_pair ( pattern.getContent ( )[ j - 1 ], repeats.getContent( )[ offset + 1 ].getSymbol ( ) ) ); + variablesSetting.insert ( std::make_pair ( pattern.getContent ( )[ j + 1 ], repeats.getContent( )[ offset + 1 ].getSymbol ( ) ) ); } - j = j - 2; } else { break; } } // match was found - if ( j == 0 ) occ.insert ( offset ); + if ( j == -1 ) occ.insert ( offset ); // shift heuristics i += bcs[subject.getContent ( )[i + pattern.getContent ( ).size ( ) - 1]]; -- GitLab