diff --git a/alib2algo/src/tree/properties/ExactSubtreeRepeats.cpp b/alib2algo/src/tree/properties/ExactSubtreeRepeats.cpp index 37503771ab176977e1c4412b10cae603bbe59c8c..99a4eef427283bc88d3f673c85d8ce541e3d47f3 100644 --- a/alib2algo/src/tree/properties/ExactSubtreeRepeats.cpp +++ b/alib2algo/src/tree/properties/ExactSubtreeRepeats.cpp @@ -8,6 +8,50 @@ #include "ExactSubtreeRepeats.h" #include <registration/AlgoRegistration.hpp> +namespace tree::properties { + +void ExactSubtreeRepeats::assignLevel ( ext::deque < unsigned > S, unsigned l, ExactSubtreeRepeats::ExactSubtreeRepeatsAux & aux ) { + + std::queue < unsigned > Q4; + ext::vector < ext::deque < unsigned > > An ( aux.treeSize ); + ext::vector < bool > Bn ( aux.treeSize ); + + while ( !S.empty ( ) ) { + unsigned i = S.front ( ); + S.pop_front ( ); + unsigned root = i + l - 1; + + if ( root < aux.treeSize - 1 ) + if ( aux.FC [ root ] ) { + unsigned k = aux.H[aux.P[root]]; + An[k].push_back ( i ); + + if ( ! Bn [ k ] ) { + Bn[k] = true; + Q4.push ( k ); + } + } + + } + + while ( !Q4.empty ( ) ) { + unsigned k = Q4.front ( ); + Q4.pop ( ); + aux.LA[k].push ( ext::make_pair ( An[k], l ) ); + + /* This is line 15 (in paper) in the Assign-Level algorithm + * It has no effect here, as I made "An" local and the function ends right after the while loop. + * I leave it here to be consistent with the algorithm. + */ + /* Bn[k] = false; + * while ( !An[k].empty ( ) ) + * An[k].pop_front ( ); + */ + } +} + +} + namespace { auto ExactRepeatsPostfixRankedTree = registration::AbstractRegister < tree::properties::ExactSubtreeRepeats, tree::PostfixRankedTree < unsigned, DefaultRankType >, const tree::PostfixRankedTree < > & > ( tree::properties::ExactSubtreeRepeats::repeats ); diff --git a/alib2algo/src/tree/properties/ExactSubtreeRepeats.h b/alib2algo/src/tree/properties/ExactSubtreeRepeats.h index 99a5a5c58a69a7c3c25d80009adc1a4e2c9dd906..798376ecc0e3bf96dd5fd4efd49801152b4237ef 100644 --- a/alib2algo/src/tree/properties/ExactSubtreeRepeats.h +++ b/alib2algo/src/tree/properties/ExactSubtreeRepeats.h @@ -272,46 +272,6 @@ void ExactSubtreeRepeats::ExactSubtreeRepeatsAux::buildFC ( const ext::vector < } } -void ExactSubtreeRepeats::assignLevel ( ext::deque < unsigned > S, unsigned l, ExactSubtreeRepeats::ExactSubtreeRepeatsAux & aux ) { - - std::queue < unsigned > Q4; - ext::vector < ext::deque < unsigned > > An ( aux.treeSize ); - ext::vector < bool > Bn ( aux.treeSize ); - - while ( !S.empty ( ) ) { - unsigned i = S.front ( ); - S.pop_front ( ); - unsigned root = i + l - 1; - - if ( root < aux.treeSize - 1 ) - if ( aux.FC [ root ] ) { - unsigned k = aux.H[aux.P[root]]; - An[k].push_back ( i ); - - if ( ! Bn [ k ] ) { - Bn[k] = true; - Q4.push ( k ); - } - } - - } - - while ( !Q4.empty ( ) ) { - unsigned k = Q4.front ( ); - Q4.pop ( ); - aux.LA[k].push ( ext::make_pair ( An[k], l ) ); - - /* This is line 15 (in paper) in the Assign-Level algorithm - * It has no effect here, as I made "An" local and the function ends right after the while loop. - * I leave it here to be consistent with the algorithm. - */ - /* Bn[k] = false; - * while ( !An[k].empty ( ) ) - * An[k].pop_front ( ); - */ - } -} - template < class SymbolType, class RankType > void ExactSubtreeRepeats::partition ( ext::deque < unsigned > S, unsigned l, int ac, const ext::vector < common::ranked_symbol < SymbolType, RankType > > & symbols, ExactSubtreeRepeats::ExactSubtreeRepeatsAux & aux ) {