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

unify interface string and tree border array

parent 14a04d5f
No related branches found
No related tags found
No related merge requests found
......@@ -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 );
......
......@@ -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();
......
......@@ -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 */
......@@ -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];
 
......
......@@ -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 ) ) );
......
......@@ -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 */
......@@ -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;
 
......
......@@ -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);
}
......
......@@ -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 ),
......
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