From 72d3f3f38536cb99be9933d04f818924f708fe8b Mon Sep 17 00:00:00 2001 From: Tomas Pecka <peckato1@fit.cvut.cz> Date: Tue, 20 Sep 2022 15:21:20 +0200 Subject: [PATCH] algo: BeginToEndIndex and SJT for PrefixBarTree Will be used for testing occurrences in ZA/PDA. --- .../arbology/transform/BeginToEndIndex.cpp | 1 + .../src/arbology/transform/BeginToEndIndex.h | 30 +++++-------------- .../src/tree/properties/SubtreeJumpTable.cpp | 1 + .../src/tree/properties/SubtreeJumpTable.h | 12 ++++++++ 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/alib2algo/src/arbology/transform/BeginToEndIndex.cpp b/alib2algo/src/arbology/transform/BeginToEndIndex.cpp index fcf6b9d8df..425585c959 100644 --- a/alib2algo/src/arbology/transform/BeginToEndIndex.cpp +++ b/alib2algo/src/arbology/transform/BeginToEndIndex.cpp @@ -5,5 +5,6 @@ namespace { auto BeginToEndIndexPrefixRankedBarTreePrefixRankedBarTree = registration::AbstractRegister < arbology::transform::BeginToEndIndex, ext::set < unsigned >, const tree::PrefixRankedBarTree < > &, const ext::set < unsigned > & > ( arbology::transform::BeginToEndIndex::transform ); auto BeginToEndIndexPrefixRankedBarTreePrefixRankedBarPattern = registration::AbstractRegister < arbology::transform::BeginToEndIndex, ext::set < unsigned >, const tree::PrefixRankedTree < > &, const ext::set < unsigned > & > ( arbology::transform::BeginToEndIndex::transform ); +auto BeginToEndIndexPrefixdBarTree = registration::AbstractRegister < arbology::transform::BeginToEndIndex, ext::set < unsigned >, const tree::PrefixBarTree < > &, const ext::set < unsigned > & > ( arbology::transform::BeginToEndIndex::transform ); } /* namespace */ diff --git a/alib2algo/src/arbology/transform/BeginToEndIndex.h b/alib2algo/src/arbology/transform/BeginToEndIndex.h index 0dcbb6791b..399448b37e 100644 --- a/alib2algo/src/arbology/transform/BeginToEndIndex.h +++ b/alib2algo/src/arbology/transform/BeginToEndIndex.h @@ -5,10 +5,9 @@ #include <tree/ranked/PrefixRankedBarTree.h> #include <tree/ranked/PrefixRankedTree.h> +#include <tree/unranked/PrefixBarTree.h> -namespace arbology { - -namespace transform { +namespace arbology::transform { /** */ @@ -18,15 +17,13 @@ public: * Search for pattern in linear string. * @return set set of occurences */ - template < class SymbolType > - static ext::set < unsigned > transform ( const tree::PrefixRankedBarTree < SymbolType > & subject, const ext::set < unsigned > & indexes ); - template < class SymbolType > - static ext::set < unsigned > transform ( const tree::PrefixRankedTree < SymbolType > & subject, const ext::set < unsigned > & indexes ); + template < class Tree > + static ext::set < unsigned > transform ( const Tree & subject, const ext::set < unsigned > & indexes ); }; -template < class SymbolType > -ext::set < unsigned > BeginToEndIndex::transform ( const tree::PrefixRankedBarTree < SymbolType > & subject, const ext::set < unsigned > & indexes ) { +template < class Tree > +ext::set < unsigned > BeginToEndIndex::transform ( const Tree & subject, const ext::set < unsigned > & indexes ) { ext::vector < int > subjectSubtreeJumpTable = tree::properties::SubtreeJumpTable::compute ( subject ); ext::set < unsigned > res; @@ -36,18 +33,5 @@ ext::set < unsigned > BeginToEndIndex::transform ( const tree::PrefixRankedBarTr return res; } -template < class SymbolType > -ext::set < unsigned > BeginToEndIndex::transform ( const tree::PrefixRankedTree < SymbolType > & subject, const ext::set < unsigned > & indexes ) { - ext::vector < int > subjectSubtreeJumpTable = tree::properties::SubtreeJumpTable::compute ( subject ); - ext::set < unsigned > res; - - for ( unsigned index : indexes ) - res.insert ( subjectSubtreeJumpTable[index] ); - - return res; -} - -} /* namespace transform */ - -} /* namespace arbology */ +} /* namespace arbology::transform */ diff --git a/alib2algo/src/tree/properties/SubtreeJumpTable.cpp b/alib2algo/src/tree/properties/SubtreeJumpTable.cpp index ae271803fe..14173a3064 100644 --- a/alib2algo/src/tree/properties/SubtreeJumpTable.cpp +++ b/alib2algo/src/tree/properties/SubtreeJumpTable.cpp @@ -10,5 +10,6 @@ auto SubtreeSizesPrefixRankedTree = registration::AbstractRegister < tree::prope auto SubtreeSizesPrefixRankedPattern = registration::AbstractRegister < tree::properties::SubtreeJumpTable, ext::vector < int >, const tree::PrefixRankedPattern < > & > ( tree::properties::SubtreeJumpTable::compute ); auto SubtreeSizesPrefixRankedExtendedPattern = registration::AbstractRegister < tree::properties::SubtreeJumpTable, ext::vector < int >, const tree::PrefixRankedExtendedPattern < > & > ( tree::properties::SubtreeJumpTable::compute ); auto SubtreeSizesPrefixRankedNonlinearPattern = registration::AbstractRegister < tree::properties::SubtreeJumpTable, ext::vector < int >, const tree::PrefixRankedNonlinearPattern < > & > ( tree::properties::SubtreeJumpTable::compute ); +auto SubtreeSizesPrefixBarTree = registration::AbstractRegister < tree::properties::SubtreeJumpTable, ext::vector < int >, const tree::PrefixBarTree < > & > ( tree::properties::SubtreeJumpTable::compute ); } /* namespace */ diff --git a/alib2algo/src/tree/properties/SubtreeJumpTable.h b/alib2algo/src/tree/properties/SubtreeJumpTable.h index 10807bef30..0086703810 100644 --- a/alib2algo/src/tree/properties/SubtreeJumpTable.h +++ b/alib2algo/src/tree/properties/SubtreeJumpTable.h @@ -9,6 +9,7 @@ #include <tree/ranked/PrefixRankedBarTree.h> #include <tree/ranked/PrefixRankedBarPattern.h> #include <tree/ranked/PrefixRankedBarNonlinearPattern.h> +#include <tree/unranked/PrefixBarTree.h> namespace tree { @@ -37,6 +38,8 @@ public: static ext::vector < int > compute ( const tree::PrefixRankedExtendedPattern < SymbolType > & pattern ); template < class SymbolType > static ext::vector < int > compute ( const tree::PrefixRankedNonlinearPattern < SymbolType > & pattern ); + template < class SymbolType > + static ext::vector < int > compute ( const tree::PrefixBarTree < SymbolType > & tree ); }; @@ -103,6 +106,15 @@ ext::vector < int > SubtreeJumpTable::compute ( const tree::PrefixRankedNonlinea return res; } +template < class SymbolType > +ext::vector < int > SubtreeJumpTable::compute ( const tree::PrefixBarTree < SymbolType > & tree ) { + ext::vector < int > res; + + buildDataPointersBar ( res, tree.getContent ( ), { tree.getBar ( ) }, 0 ); + + return res; +} + /** * used to compute subtree jump table. * @param begin - index of a root node of a complete subtree to process -- GitLab