diff --git a/alib2algo/src/string/properties/BorderArray.h b/alib2algo/src/string/properties/BorderArray.h index f26d6718fabc5d2e6a4e5081bcaecd33937151c6..1d8b5d585f3e43bf7d9e1bef4d0ddcd568f5de32 100644 --- a/alib2algo/src/string/properties/BorderArray.h +++ b/alib2algo/src/string/properties/BorderArray.h @@ -31,7 +31,7 @@ ext::vector<size_t> BorderArray::construct(const string::LinearString < SymbolTy const auto& w = string.getContent(); ext::vector<size_t> res(w.size() + 1); - res[0] = 0; + res[0] = -1; res[1] = 0; for(size_t i = 1; i < w.size(); i++) { size_t b = res[i]; diff --git a/alib2algo/src/stringology/exact/KnuthMorrisPratt.h b/alib2algo/src/stringology/exact/KnuthMorrisPratt.h index 9d6cf6bd0df7517b2e7c710053bc646273fb35a8..44a520e82502d20a2bc94721fa58d742d49a5c05 100644 --- a/alib2algo/src/stringology/exact/KnuthMorrisPratt.h +++ b/alib2algo/src/stringology/exact/KnuthMorrisPratt.h @@ -58,8 +58,12 @@ ext::set < unsigned > KnuthMorrisPratt::match ( const string::LinearString < Sym if ( j >= pattern.getContent ( ).size ( ) ) occ.insert ( i ); // shift heristics - i += j - ba[j]; - j = ba[j]; + if ( j != 0 ) { + i += j - ba[j]; + j = ba[j]; + } else { + i += 1; + } } //measurements::end(); diff --git a/alib2integrationtest/test-src/tests/exactMatching.cpp b/alib2integrationtest/test-src/tests/exactMatching.cpp index 10129014d0b9676577e20c84327d04b28bafe07c..41a6c7763dff5440bdf90a1649faa1f790883e87 100644 --- a/alib2integrationtest/test-src/tests/exactMatching.cpp +++ b/alib2integrationtest/test-src/tests/exactMatching.cpp @@ -26,7 +26,7 @@ static std::string qGenString ( const size_t & len, const size_t &alph_len, cons TEST_CASE ( "ExactMatching", "[integration]" ) { auto definition = GENERATE ( as < std::tuple < std::string, std::string, bool > > ( ), std::make_tuple ( "Exact Boyer Moore", "stringology::exact::BoyerMoore $subject $pattern", true ), - std::make_tuple ( "Exact Knuth Morris Pratt", "stringology::exact::KnuthMorrisPratt $subject $pattern", true ), + std::make_tuple ( "Exact Knuth Morris Pratt", "stringology::exact::KnuthMorrisPratt $subject $pattern", false ), std::make_tuple ( "Exact Boyer Moore Horspool", " stringology::exact::BoyerMooreHorspool $subject $pattern", true ), std::make_tuple ( "Exact Reversed Boyer Moore Horspool", " stringology::exact::ReversedBoyerMooreHorspool $subject $pattern", true ), std::make_tuple ( "Quick Search", "stringology::exact::QuickSearch $subject $pattern", true ),