From fe3fe5bc4f72b1f61b576ea9c2a4c71343048d84 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Mon, 8 Jul 2019 10:19:19 +0200 Subject: [PATCH] unify interface string and tree border array --- ...eadZoneUsingBadCharacterShiftAndBorderArray.h | 4 ++-- alib2algo/src/arbology/exact/KnuthMorrisPratt.h | 16 ++++++++-------- alib2algo/src/string/properties/BorderArray.cpp | 2 +- alib2algo/src/string/properties/BorderArray.h | 8 ++++---- .../src/string/properties/GoodSuffixShiftTable.h | 2 +- .../src/tree/properties/BorderArrayNaive.cpp | 8 ++++---- alib2algo/src/tree/properties/BorderArrayNaive.h | 16 ++++++++-------- .../string/properties/borderArrayTest.cpp | 4 ++-- .../test-src/tests/exactMatching.cpp | 1 + 9 files changed, 31 insertions(+), 30 deletions(-) diff --git a/alib2algo/src/arbology/exact/DeadZoneUsingBadCharacterShiftAndBorderArray.h b/alib2algo/src/arbology/exact/DeadZoneUsingBadCharacterShiftAndBorderArray.h index a12e45e2a1..09d114c3f3 100644 --- a/alib2algo/src/arbology/exact/DeadZoneUsingBadCharacterShiftAndBorderArray.h +++ b/alib2algo/src/arbology/exact/DeadZoneUsingBadCharacterShiftAndBorderArray.h @@ -62,7 +62,7 @@ template < class SymbolType > ext::set < unsigned > DeadZoneUsingBadCharacterShiftAndBorderArray::match ( const tree::PrefixRankedBarTree < SymbolType > & subject, const tree::PrefixRankedBarPattern < SymbolType > & pattern ) { ext::set < unsigned > occ; ext::map < common::ranked_symbol < SymbolType >, size_t > bbcs = tree::properties::ReversedBadCharacterShiftTable::bcs ( pattern ); // NOTE: the subjects alphabet must be a subset or equal to the pattern - ext::vector < size_t > fba = tree::properties::BorderArrayNaive::ba ( pattern ); + ext::vector < size_t > fba = tree::properties::BorderArrayNaive::construct ( pattern ); ext::vector < int > subjectSubtreeJumpTable = tree::properties::SubtreeJumpTable::compute ( subject ); match_rec ( occ, subject, pattern, fba, bbcs, subjectSubtreeJumpTable, 0, subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( ) + 1 ); @@ -94,7 +94,7 @@ template < class SymbolType > ext::set < unsigned > DeadZoneUsingBadCharacterShiftAndBorderArray::match ( const tree::PrefixRankedTree < SymbolType > & subject, const tree::PrefixRankedPattern < SymbolType > & pattern ) { ext::set < unsigned > occ; ext::map < common::ranked_symbol < SymbolType >, size_t > bbcs = tree::properties::ReversedBadCharacterShiftTable::bcs ( pattern ); // NOTE: the subjects alphabet must be a subset or equal to the pattern - ext::vector < size_t > fba = tree::properties::BorderArrayNaive::ba ( pattern ); + ext::vector < size_t > fba = tree::properties::BorderArrayNaive::construct ( pattern ); ext::vector < int > subjectSubtreeJumpTable = tree::properties::SubtreeJumpTable::compute ( subject ); match_rec ( occ, subject, pattern, fba, bbcs, subjectSubtreeJumpTable, 0, subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( ) + 1 ); diff --git a/alib2algo/src/arbology/exact/KnuthMorrisPratt.h b/alib2algo/src/arbology/exact/KnuthMorrisPratt.h index 9917dc2321..b8fbc76122 100644 --- a/alib2algo/src/arbology/exact/KnuthMorrisPratt.h +++ b/alib2algo/src/arbology/exact/KnuthMorrisPratt.h @@ -63,7 +63,7 @@ ext::set < unsigned > KnuthMorrisPratt::match ( const tree::PrefixRankedBarTree template < class SymbolType > ext::set < unsigned > KnuthMorrisPratt::match ( const tree::PrefixRankedBarTree < SymbolType > & subject, const tree::PrefixRankedBarPattern < SymbolType > & pattern ) { ext::set < unsigned > occ; - ext::vector < size_t > ba = tree::properties::BorderArrayNaive::ba ( pattern ); + ext::vector < size_t > construct = tree::properties::BorderArrayNaive::construct ( pattern ); //measurements::start("Algorithm", measurements::Type::MAIN); @@ -81,7 +81,7 @@ ext::set < unsigned > KnuthMorrisPratt::match ( const tree::PrefixRankedBarTree if ( j >= pattern.getContent ( ).size ( ) ) occ.insert ( i ); // shift heuristics - i += j - ba[j]; + i += j - construct[j]; } //measurements::end(); @@ -92,7 +92,7 @@ ext::set < unsigned > KnuthMorrisPratt::match ( const tree::PrefixRankedBarTree template < class SymbolType > ext::set < unsigned > KnuthMorrisPratt::match ( const tree::PrefixRankedBarTree < SymbolType > & subject, const tree::PrefixRankedBarNonlinearPattern < SymbolType > & pattern ) { ext::set < unsigned > occ; - ext::vector < size_t > ba = tree::properties::BorderArrayNaive::ba ( pattern ); + ext::vector < size_t > construct = tree::properties::BorderArrayNaive::construct ( pattern ); //measurements::start("Algorithm", measurements::Type::MAIN); @@ -111,7 +111,7 @@ ext::set < unsigned > KnuthMorrisPratt::match ( const tree::PrefixRankedBarTree if ( j >= pattern.getContent ( ).size ( ) ) occ.insert ( i ); // shift heuristics - i += j - ba[j]; + i += j - construct[j]; } //measurements::end(); @@ -127,7 +127,7 @@ ext::set < unsigned > KnuthMorrisPratt::match ( const tree::PrefixRankedTree < S template < class SymbolType > ext::set < unsigned > KnuthMorrisPratt::match ( const tree::PrefixRankedTree < SymbolType > & subject, const tree::PrefixRankedPattern < SymbolType > & pattern ) { ext::set < unsigned > occ; - ext::vector < size_t > ba = tree::properties::BorderArrayNaive::ba ( pattern ); + ext::vector < size_t > construct = tree::properties::BorderArrayNaive::construct ( pattern ); //measurements::start("Algorithm", measurements::Type::MAIN); @@ -145,7 +145,7 @@ ext::set < unsigned > KnuthMorrisPratt::match ( const tree::PrefixRankedTree < S if ( j >= pattern.getContent ( ).size ( ) ) occ.insert ( i ); // shift heristics - i += j - ba[j]; + i += j - construct[j]; } //measurements::end(); @@ -156,7 +156,7 @@ ext::set < unsigned > KnuthMorrisPratt::match ( const tree::PrefixRankedTree < S template < class SymbolType > ext::set < unsigned > KnuthMorrisPratt::match ( const tree::PrefixRankedTree < SymbolType > & subject, const tree::PrefixRankedNonlinearPattern < SymbolType > & pattern ) { ext::set < unsigned > occ; - ext::vector < size_t > ba = tree::properties::BorderArrayNaive::ba ( pattern ); + ext::vector < size_t > construct = tree::properties::BorderArrayNaive::construct ( pattern ); //measurements::start("Algorithm", measurements::Type::MAIN); @@ -175,7 +175,7 @@ ext::set < unsigned > KnuthMorrisPratt::match ( const tree::PrefixRankedTree < S if ( j >= pattern.getContent ( ).size ( ) ) occ.insert ( i ); // shift heristics - i += j - ba[j]; + i += j - construct[j]; } //measurements::end(); diff --git a/alib2algo/src/string/properties/BorderArray.cpp b/alib2algo/src/string/properties/BorderArray.cpp index 6cf11be334..99fe3c61cf 100644 --- a/alib2algo/src/string/properties/BorderArray.cpp +++ b/alib2algo/src/string/properties/BorderArray.cpp @@ -10,6 +10,6 @@ namespace { -auto BorderArrayLinearString = registration::AbstractRegister < string::properties::BorderArray, ext::vector < unsigned >, const string::LinearString < > & > ( string::properties::BorderArray::construct ); +auto BorderArrayLinearString = registration::AbstractRegister < string::properties::BorderArray, ext::vector < size_t >, const string::LinearString < > & > ( string::properties::BorderArray::construct ); } /* namespace */ diff --git a/alib2algo/src/string/properties/BorderArray.h b/alib2algo/src/string/properties/BorderArray.h index 7d63d94298..f41a971da6 100644 --- a/alib2algo/src/string/properties/BorderArray.h +++ b/alib2algo/src/string/properties/BorderArray.h @@ -23,18 +23,18 @@ public: * @return Vector of length same as string, where i-th index corresponds to i-th element of string */ template < class SymbolType > - static ext::vector<unsigned> construct(const string::LinearString < SymbolType >& string); + static ext::vector<size_t> construct(const string::LinearString < SymbolType >& string); }; template < class SymbolType > -ext::vector<unsigned> BorderArray::construct(const string::LinearString < SymbolType >& string) { +ext::vector<size_t> BorderArray::construct(const string::LinearString < SymbolType >& string) { const auto& w = string.getContent(); - ext::vector<unsigned> res(w.size() + 1); + ext::vector<size_t> res(w.size() + 1); res[0] = 0; res[1] = 0; for(size_t i = 1; i < w.size(); i++) { - unsigned b = res[i]; + size_t b = res[i]; while (b > 0 && w[i + 1 - 1] != w[b + 1 - 1]) b = res[b]; diff --git a/alib2algo/src/string/properties/GoodSuffixShiftTable.h b/alib2algo/src/string/properties/GoodSuffixShiftTable.h index 19511ec2d1..ec516392b2 100644 --- a/alib2algo/src/string/properties/GoodSuffixShiftTable.h +++ b/alib2algo/src/string/properties/GoodSuffixShiftTable.h @@ -41,7 +41,7 @@ ext::vector < size_t > GoodSuffixShiftTable::gss ( const string::LinearString < std::reverse ( content.begin ( ), content.end ( ) ); string::LinearString < SymbolType > reversed ( std::move ( content ) ); - ext::vector < unsigned > borderArray = string::properties::BorderArray::construct ( reversed ); + ext::vector < size_t > borderArray = string::properties::BorderArray::construct ( reversed ); size_t max = reversed.getContent ( ).size ( ) - borderArray.back ( ); automaton::DFA < DefaultSymbolType, ext::set < unsigned > > factorAutomaton = automaton::determinize::Determinize::determinize ( automaton::simplify::EpsilonRemoverIncoming::remove ( stringology::indexing::NondeterministicExactFactorAutomaton::construct ( reversed ) ) ); diff --git a/alib2algo/src/tree/properties/BorderArrayNaive.cpp b/alib2algo/src/tree/properties/BorderArrayNaive.cpp index 6a233b91fe..8b82129cdc 100644 --- a/alib2algo/src/tree/properties/BorderArrayNaive.cpp +++ b/alib2algo/src/tree/properties/BorderArrayNaive.cpp @@ -10,9 +10,9 @@ namespace { -auto BorderArrayPrefixRankedBarNonlinearPattern = registration::AbstractRegister < tree::properties::BorderArrayNaive, ext::vector < size_t >, const tree::PrefixRankedBarNonlinearPattern < > & > ( tree::properties::BorderArrayNaive::ba ); -auto BorderArrayPrefixRankedBarPattern = registration::AbstractRegister < tree::properties::BorderArrayNaive, ext::vector < size_t >, const tree::PrefixRankedBarPattern < > & > ( tree::properties::BorderArrayNaive::ba ); -auto BorderArrayPrefixRankedNonlinearPattern = registration::AbstractRegister < tree::properties::BorderArrayNaive, ext::vector < size_t >, const tree::PrefixRankedNonlinearPattern < > & > ( tree::properties::BorderArrayNaive::ba ); -auto BorderArrayPrefixRankedPattern = registration::AbstractRegister < tree::properties::BorderArrayNaive, ext::vector < size_t >, const tree::PrefixRankedPattern < > & > ( tree::properties::BorderArrayNaive::ba ); +auto BorderArrayPrefixRankedBarNonlinearPattern = registration::AbstractRegister < tree::properties::BorderArrayNaive, ext::vector < size_t >, const tree::PrefixRankedBarNonlinearPattern < > & > ( tree::properties::BorderArrayNaive::construct ); +auto BorderArrayPrefixRankedBarPattern = registration::AbstractRegister < tree::properties::BorderArrayNaive, ext::vector < size_t >, const tree::PrefixRankedBarPattern < > & > ( tree::properties::BorderArrayNaive::construct ); +auto BorderArrayPrefixRankedNonlinearPattern = registration::AbstractRegister < tree::properties::BorderArrayNaive, ext::vector < size_t >, const tree::PrefixRankedNonlinearPattern < > & > ( tree::properties::BorderArrayNaive::construct ); +auto BorderArrayPrefixRankedPattern = registration::AbstractRegister < tree::properties::BorderArrayNaive, ext::vector < size_t >, const tree::PrefixRankedPattern < > & > ( tree::properties::BorderArrayNaive::construct ); } /* namespace */ diff --git a/alib2algo/src/tree/properties/BorderArrayNaive.h b/alib2algo/src/tree/properties/BorderArrayNaive.h index f08f8fbe17..44ee001b78 100644 --- a/alib2algo/src/tree/properties/BorderArrayNaive.h +++ b/alib2algo/src/tree/properties/BorderArrayNaive.h @@ -46,28 +46,28 @@ public: * @return set set of occurences */ template < class SymbolType > - static ext::vector < size_t > ba ( const tree::PrefixRankedBarNonlinearPattern < SymbolType > & pattern ); + static ext::vector < size_t > construct ( const tree::PrefixRankedBarNonlinearPattern < SymbolType > & pattern ); /** * Search for pattern in linear string. * @return set set of occurences */ template < class SymbolType > - static ext::vector < size_t > ba ( const tree::PrefixRankedBarPattern < SymbolType > & pattern ); + static ext::vector < size_t > construct ( const tree::PrefixRankedBarPattern < SymbolType > & pattern ); /** * Search for pattern in linear string. * @return set set of occurences */ template < class SymbolType > - static ext::vector < size_t > ba ( const tree::PrefixRankedNonlinearPattern < SymbolType > & pattern ); + static ext::vector < size_t > construct ( const tree::PrefixRankedNonlinearPattern < SymbolType > & pattern ); /** * Search for pattern in linear string. * @return set set of occurences */ template < class SymbolType > - static ext::vector < size_t > ba ( const tree::PrefixRankedPattern < SymbolType > & pattern ); + static ext::vector < size_t > construct ( const tree::PrefixRankedPattern < SymbolType > & pattern ); }; @@ -91,7 +91,7 @@ bool BorderArrayNaive::matches ( const tree::PrefixRankedBarNonlinearPattern < S } template < class SymbolType > -ext::vector < size_t > BorderArrayNaive::ba ( const tree::PrefixRankedBarNonlinearPattern < SymbolType > & pattern ) { +ext::vector < size_t > BorderArrayNaive::construct ( const tree::PrefixRankedBarNonlinearPattern < SymbolType > & pattern ) { ext::vector < int > patternSubtreeJumpTable = SubtreeJumpTable::compute ( pattern ); ext::vector < size_t > res; @@ -137,7 +137,7 @@ bool BorderArrayNaive::matches ( const tree::PrefixRankedBarPattern < SymbolType } template < class SymbolType > -ext::vector < size_t > BorderArrayNaive::ba ( const tree::PrefixRankedBarPattern < SymbolType > & pattern ) { +ext::vector < size_t > BorderArrayNaive::construct ( const tree::PrefixRankedBarPattern < SymbolType > & pattern ) { ext::vector < int > patternSubtreeJumpTable = SubtreeJumpTable::compute ( pattern ); ext::vector < size_t > res; @@ -184,7 +184,7 @@ bool BorderArrayNaive::matches ( const tree::PrefixRankedNonlinearPattern < Symb } template < class SymbolType > -ext::vector < size_t > BorderArrayNaive::ba ( const tree::PrefixRankedNonlinearPattern < SymbolType > & pattern ) { +ext::vector < size_t > BorderArrayNaive::construct ( const tree::PrefixRankedNonlinearPattern < SymbolType > & pattern ) { ext::vector < int > patternSubtreeJumpTable = SubtreeJumpTable::compute ( pattern ); ext::vector < size_t > res; @@ -230,7 +230,7 @@ bool BorderArrayNaive::matches ( const tree::PrefixRankedPattern < SymbolType > } template < class SymbolType > -ext::vector < size_t > BorderArrayNaive::ba ( const tree::PrefixRankedPattern < SymbolType > & pattern ) { +ext::vector < size_t > BorderArrayNaive::construct ( const tree::PrefixRankedPattern < SymbolType > & pattern ) { ext::vector < int > patternSubtreeJumpTable = SubtreeJumpTable::compute ( pattern ); ext::vector < size_t > res; diff --git a/alib2algo/test-src/string/properties/borderArrayTest.cpp b/alib2algo/test-src/string/properties/borderArrayTest.cpp index 11c6ead408..7aa83d487a 100644 --- a/alib2algo/test-src/string/properties/borderArrayTest.cpp +++ b/alib2algo/test-src/string/properties/borderArrayTest.cpp @@ -5,8 +5,8 @@ TEST_CASE ( "Border Array", "[unit][algo][string][properties]" ) { SECTION ( "Test" ) { string::LinearString < char > string ( "alfalfaalf" ); - ext::vector<unsigned> borderArray = string::properties::BorderArray::construct(string); - ext::vector<unsigned> expected {0, 0, 0, 0, 1, 2, 3, 1, 1, 2, 3}; + ext::vector<size_t> borderArray = string::properties::BorderArray::construct(string); + ext::vector<size_t> expected {0, 0, 0, 0, 1, 2, 3, 1, 1, 2, 3}; CHECK(borderArray != expected); } diff --git a/alib2integrationtest/test-src/tests/exactMatching.cpp b/alib2integrationtest/test-src/tests/exactMatching.cpp index d6b34df65d..10129014d0 100644 --- a/alib2integrationtest/test-src/tests/exactMatching.cpp +++ b/alib2integrationtest/test-src/tests/exactMatching.cpp @@ -26,6 +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 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 ), -- GitLab