From b8e8925192a30ac5b58d28cf3e578daa8ce3a140 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Wed, 4 Apr 2018 12:58:46 +0200 Subject: [PATCH] fix some S |S pattern related issues in BCS like algos --- alib2algo/src/arbology/exact/ReversedBoyerMooreHorspool.h | 8 ++++---- alib2algo/src/arbology/exact/ReversedQuickSearch.h | 8 ++++---- alib2algo/src/tree/exact/BackwardOccurrenceTest.h | 4 ++-- alib2algo/src/tree/exact/ForwardOccurrenceTest.h | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/alib2algo/src/arbology/exact/ReversedBoyerMooreHorspool.h b/alib2algo/src/arbology/exact/ReversedBoyerMooreHorspool.h index 626cc889b5..d5031de947 100644 --- a/alib2algo/src/arbology/exact/ReversedBoyerMooreHorspool.h +++ b/alib2algo/src/arbology/exact/ReversedBoyerMooreHorspool.h @@ -65,7 +65,7 @@ ext::set < unsigned > ReversedBoyerMooreHorspool::match ( const tree::PrefixRank ext::vector < int > subjectSubtreeJumpTable = tree::properties::SubtreeJumpTable::compute ( subject ); // index to the subject - int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( ) + 1; + int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( ); // main loop of the algorithm over all possible indexes where the pattern can start while ( i >= 0 ) { @@ -92,7 +92,7 @@ ext::set < unsigned > ReversedBoyerMooreHorspool::match ( const tree::PrefixRank tree::PrefixRankedBarTree < unsigned, RankType > repeats = tree::properties::ExactSubtreeRepeatsNaive::repeats ( subject ); // index to the subject - int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( ) + 1; + int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( ); // main loop of the algorithm over all possible indexes where the pattern can start while ( i >= 0 ) { @@ -121,7 +121,7 @@ ext::set < unsigned > ReversedBoyerMooreHorspool::match ( const tree::PrefixRank ext::vector < int > subjectSubtreeJumpTable = tree::properties::SubtreeJumpTable::compute ( subject ); // index to the subject - int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( ) + 1; + int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( ); // main loop of the algorithm over all possible indexes where the pattern can start while ( i >= 0 ) { @@ -148,7 +148,7 @@ ext::set < unsigned > ReversedBoyerMooreHorspool::match ( const tree::PrefixRank tree::PrefixRankedTree < unsigned, RankType > repeats = tree::properties::ExactSubtreeRepeatsNaive::repeats ( subject ); // index to the subject - int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( ) + 1; + int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( ); // main loop of the algorithm over all possible indexes where the pattern can start while ( i >= 0 ) { diff --git a/alib2algo/src/arbology/exact/ReversedQuickSearch.h b/alib2algo/src/arbology/exact/ReversedQuickSearch.h index 8fdd64a459..55452941a7 100644 --- a/alib2algo/src/arbology/exact/ReversedQuickSearch.h +++ b/alib2algo/src/arbology/exact/ReversedQuickSearch.h @@ -66,7 +66,7 @@ ext::set < unsigned > ReversedQuickSearch::match ( const tree::PrefixRankedBarTr ext::vector < int > subjectSubtreeJumpTable = tree::properties::SubtreeJumpTable::compute ( subject ); // index to the subject - int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( ) + 1; + int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( ); // main loop of the algorithm over all possible indexes where the pattern can start while ( i >= 0 ) { @@ -100,7 +100,7 @@ ext::set < unsigned > ReversedQuickSearch::match ( const tree::PrefixRankedBarTr tree::PrefixRankedBarTree < unsigned, RankType > repeats = tree::properties::ExactSubtreeRepeatsNaive::repeats ( subject ); // index to the subject - int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( ) + 1; + int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( ); // main loop of the algorithm over all possible indexes where the pattern can start while ( i >= 0 ) { @@ -135,7 +135,7 @@ ext::set < unsigned > ReversedQuickSearch::match ( const tree::PrefixRankedTree ext::vector < int > subjectSubtreeJumpTable = tree::properties::SubtreeJumpTable::compute ( subject ); // index to the subject - int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( ) + 1; + int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( ); // main loop of the algorithm over all possible indexes where the pattern can start while ( i >= 0 ) { @@ -166,7 +166,7 @@ ext::set < unsigned > ReversedQuickSearch::match ( const tree::PrefixRankedTree tree::PrefixRankedTree < unsigned, RankType > repeats = tree::properties::ExactSubtreeRepeatsNaive::repeats ( subject ); // index to the subject - int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( ) + 1; + int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( ); // main loop of the algorithm over all possible indexes where the pattern can start while ( i >= 0 ) { diff --git a/alib2algo/src/tree/exact/BackwardOccurrenceTest.h b/alib2algo/src/tree/exact/BackwardOccurrenceTest.h index 3a0e46afa5..87bba31869 100644 --- a/alib2algo/src/tree/exact/BackwardOccurrenceTest.h +++ b/alib2algo/src/tree/exact/BackwardOccurrenceTest.h @@ -50,7 +50,7 @@ ext::pair < int, int > BackwardOccurrenceTest::occurrence ( const PrefixRankedBa // match of symbol offset = offset - 1; j = j - 1; - } else if ( ( pattern.getContent ( )[j] == pattern.getVariablesBar ( ) ) /* && ( pattern.getBars ( ).count ( subject.getContent ( )[offset] ) ) */ ) { + } else if ( ( pattern.getContent ( )[j] == pattern.getVariablesBar ( ) ) && ( subject.getBars ( ).count ( subject.getContent ( )[offset] ) ) ) { //the second part of the condition is needed to handle S |S // match of variable with subtree offset = subjectSubtreeJumpTable[offset]; j = j - 2; @@ -79,7 +79,7 @@ ext::pair < int, int > BackwardOccurrenceTest::occurrence ( const PrefixRankedBa // match of symbol offset = offset - 1; j = j - 1; - } else if ( ( pattern.getContent ( )[j] == pattern.getVariablesBar ( ) ) /* && ( pattern.getBars ( ).count ( subject.getContent ( )[offset] ) ) */ ) { + } else if ( ( pattern.getContent ( )[j] == pattern.getVariablesBar ( ) ) && ( subject.getBars ( ).count ( subject.getContent ( )[offset] ) ) ) { //the second part of the condition is needed to handle S |S // else match of variable with subtree offset = subjectSubtreeJumpTable[offset]; j = j - 2; diff --git a/alib2algo/src/tree/exact/ForwardOccurrenceTest.h b/alib2algo/src/tree/exact/ForwardOccurrenceTest.h index cf97699cc1..62dd723c88 100644 --- a/alib2algo/src/tree/exact/ForwardOccurrenceTest.h +++ b/alib2algo/src/tree/exact/ForwardOccurrenceTest.h @@ -54,7 +54,7 @@ size_t ForwardOccurrenceTest::occurrence ( const PrefixRankedBarTree < SymbolTyp // match of symbol offset = offset + 1; j = j + 1; - } else if ( ( pattern.getContent ( )[j] == pattern.getSubtreeWildcard ( ) ) /* && ( ! pattern.getBars ( ).count ( subject.getContent ( )[offset] ) ) */ ) { + } else if ( ( pattern.getContent ( )[j] == pattern.getSubtreeWildcard ( ) ) && ( ! subject.getBars ( ).count ( subject.getContent ( )[offset] ) ) ) { //the second part of the condition is needed to handle S |S // match of variable with subtree offset = subjectSubtreeJumpTable[offset]; j = j + 2; @@ -81,7 +81,7 @@ size_t ForwardOccurrenceTest::occurrence ( const PrefixRankedBarTree < SymbolTyp // match of symbol offset = offset + 1; j = j + 1; - } else if ( ( pattern.getContent ( )[j] == pattern.getSubtreeWildcard ( ) || pattern.getNonlinearVariables ( ).count ( pattern.getContent ( )[j] ) ) /* && ( ! pattern.getBars ( ).count ( subject.getContent ( )[offset] ) ) */ ) { + } else if ( ( pattern.getContent ( )[j] == pattern.getSubtreeWildcard ( ) || pattern.getNonlinearVariables ( ).count ( pattern.getContent ( )[j] ) ) && ( ! subject.getBars ( ).count ( subject.getContent ( )[offset] ) ) ) { //the second part of the condition is needed to handle S |S // check nonlinear variable if ( pattern.getNonlinearVariables ( ).count ( pattern.getContent ( )[ j ] ) ) { auto setting = variablesSetting.find ( pattern.getContent ( )[ j ] ); -- GitLab