From f40bec89c6f20285dd3f9688d4c1b3ccd1f0aaf1 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Wed, 14 Feb 2018 20:01:04 +0100 Subject: [PATCH] revise casting helper functions --- alib2data/src/tree/common/TreeAuxiliary.h | 137 +++++++++++++++++- alib2data/src/tree/ranked/PostfixRankedTree.h | 15 +- .../ranked/PrefixRankedBarNonlinearPattern.h | 24 +-- .../src/tree/ranked/PrefixRankedBarPattern.h | 20 +-- .../src/tree/ranked/PrefixRankedBarTree.h | 17 +-- .../ranked/PrefixRankedNonlinearPattern.h | 19 +-- .../src/tree/ranked/PrefixRankedPattern.h | 15 +- alib2data/src/tree/ranked/PrefixRankedTree.h | 41 +----- .../src/tree/ranked/RankedNonlinearPattern.h | 2 +- alib2data/src/tree/ranked/RankedPattern.h | 2 +- alib2data/src/tree/ranked/RankedTree.h | 4 +- alib2data/src/tree/unranked/PrefixBarTree.h | 18 +-- .../tree/unranked/UnrankedNonlinearPattern.h | 2 +- alib2data/src/tree/unranked/UnrankedPattern.h | 2 +- alib2data/src/tree/unranked/UnrankedTree.h | 2 +- 15 files changed, 153 insertions(+), 167 deletions(-) diff --git a/alib2data/src/tree/common/TreeAuxiliary.h b/alib2data/src/tree/common/TreeAuxiliary.h index 7dc9cbf0ff..81aeeed882 100644 --- a/alib2data/src/tree/common/TreeAuxiliary.h +++ b/alib2data/src/tree/common/TreeAuxiliary.h @@ -21,6 +21,9 @@ namespace tree { * Parser used to get tree from XML parsed into list of Tokens. */ class TreeAuxiliary { + template < class SymbolType, class RankType > + static void postfixToPrefixInt ( const ext::vector < common::ranked_symbol < SymbolType, RankType > > & src, ext::vector < common::ranked_symbol < SymbolType, RankType > > & dest, unsigned & readIndex ); + public: template < class SymbolType, class RankType > static ext::set < SymbolType > unrankSymbols ( const ext::set < common::ranked_symbol < SymbolType, RankType > > & alphabet ); @@ -28,12 +31,29 @@ public: static ext::set < common::ranked_symbol < SymbolType, RankType > > computeBars ( const ext::set < common::ranked_symbol < SymbolType, RankType > > & alphabet, const SymbolType & barBase ); template < class SymbolType, class RankType > - static ext::tree < common::ranked_symbol < SymbolType, RankType > > toRankedTree ( const ext::tree < SymbolType > & from ); + static ext::tree < common::ranked_symbol < SymbolType, RankType > > unrankedToRanked ( const ext::tree < SymbolType > & from ); + template < class SymbolType, class RankType > + static ext::tree < SymbolType > rankedToUnranked ( const ext::tree < common::ranked_symbol < SymbolType, RankType > > & from ); + + template < class SymbolType, class RankType > + static ext::tree < common::ranked_symbol < SymbolType, RankType > > postfixToTree (const ext::vector < common::ranked_symbol < SymbolType, RankType > > & from); + + template < class SymbolType, class RankType > + static ext::vector < common::ranked_symbol < SymbolType, RankType > > postfixToPrefix ( const ext::vector < common::ranked_symbol < SymbolType, RankType > > & src ); + + template < class SymbolType, class RankType > + static ext::vector < common::ranked_symbol < SymbolType, RankType > > treeToPrefix ( const ext::tree < common::ranked_symbol < SymbolType, RankType > > & tree ); + template < class SymbolType > + static ext::vector < SymbolType > treeToPrefix ( const ext::tree < SymbolType > & tree, const SymbolType & bar ); template < class SymbolType, class RankType > - static ext::tree < common::ranked_symbol < SymbolType, RankType > > postfixToRankedTree (const ext::vector < common::ranked_symbol < SymbolType, RankType > > & from); + static ext::vector < common::ranked_symbol < SymbolType, RankType > > treeToPrefix ( const ext::tree < common::ranked_symbol < SymbolType, RankType > > & tree, const SymbolType & barBase ); template < class SymbolType, class RankType > - static ext::tree < SymbolType > toUnrankedTree ( const ext::tree < common::ranked_symbol < SymbolType, RankType > > & from ); + static ext::vector < common::ranked_symbol < SymbolType, RankType > > treeToPrefix ( const ext::tree < common::ranked_symbol < SymbolType, RankType > > & tree, const common::ranked_symbol < SymbolType, RankType > & subtreeWildcard, const SymbolType & barBase, const common::ranked_symbol < SymbolType, RankType > & variablesBar ); + template < class SymbolType, class RankType > + static ext::vector < common::ranked_symbol < SymbolType, RankType > > treeToPrefix ( const ext::tree < common::ranked_symbol < SymbolType, RankType > > & tree, const common::ranked_symbol < SymbolType, RankType > & subtreeWildcard, const ext::set < common::ranked_symbol < SymbolType, RankType > > & nonlinearVariables, const SymbolType & barBase, const common::ranked_symbol < SymbolType, RankType > & variablesBar ); + template < class SymbolType, class RankType > + static ext::vector < common::ranked_symbol < SymbolType, RankType > > treeToPostfix ( const ext::tree < common::ranked_symbol < SymbolType, RankType > > & tree ); }; template < class SymbolType, class RankType > @@ -51,11 +71,11 @@ ext::set < common::ranked_symbol < SymbolType, RankType > > TreeAuxiliary::compu } template < class SymbolType, class RankType > -ext::tree < common::ranked_symbol < SymbolType, RankType > > TreeAuxiliary::toRankedTree ( const ext::tree < SymbolType > & tree ) { +ext::tree < common::ranked_symbol < SymbolType, RankType > > TreeAuxiliary::unrankedToRanked ( const ext::tree < SymbolType > & tree ) { ext::vector < ext::tree < common::ranked_symbol < SymbolType, RankType > > > children; for ( const ext::tree < SymbolType > & child : tree ) { - children.push_back ( toRankedTree < SymbolType, RankType > ( child ) ); + children.push_back ( unrankedToRanked < SymbolType, RankType > ( child ) ); } unsigned size = children.size ( ); @@ -63,7 +83,7 @@ ext::tree < common::ranked_symbol < SymbolType, RankType > > TreeAuxiliary::toRa } template < class SymbolType, class RankType > -ext::tree < common::ranked_symbol < SymbolType, RankType > > TreeAuxiliary::postfixToRankedTree ( const ext::vector < common::ranked_symbol < SymbolType, RankType > > & from ) { +ext::tree < common::ranked_symbol < SymbolType, RankType > > TreeAuxiliary::postfixToTree ( const ext::vector < common::ranked_symbol < SymbolType, RankType > > & from ) { std::stack < ext::tree < common::ranked_symbol < SymbolType, RankType > > > tree_stack; @@ -92,16 +112,117 @@ ext::tree < common::ranked_symbol < SymbolType, RankType > > TreeAuxiliary::post template < class SymbolType, class RankType > -ext::tree < SymbolType > TreeAuxiliary::toUnrankedTree ( const ext::tree < common::ranked_symbol < SymbolType, RankType > > & tree ) { +ext::tree < SymbolType > TreeAuxiliary::rankedToUnranked ( const ext::tree < common::ranked_symbol < SymbolType, RankType > > & tree ) { ext::vector < ext::tree < SymbolType > > children; for ( const ext::tree < common::ranked_symbol < SymbolType, RankType > > & child : tree ) { - children.push_back ( toUnrankedTree < SymbolType, RankType > ( child ) ); + children.push_back ( rankedToUnranked < SymbolType, RankType > ( child ) ); } return ext::tree < SymbolType > ( tree.getData ( ).getSymbol ( ), std::move ( children ) ); } +template < class SymbolType, class RankType > +ext::vector < common::ranked_symbol < SymbolType, RankType > > TreeAuxiliary::postfixToPrefix ( const ext::vector < common::ranked_symbol < SymbolType, RankType > > & src ) { + unsigned readIndex = src.size ( ) - 1; + + ext::vector < common::ranked_symbol < SymbolType, RankType > > dest; + postfixToPrefixInt ( src, dest, readIndex ); + + std::reverse ( dest.begin ( ), dest.end ( ) ); + + return dest; +} + +template < class SymbolType, class RankType > +void TreeAuxiliary::postfixToPrefixInt ( const ext::vector < common::ranked_symbol < SymbolType, RankType > > & src, ext::vector < common::ranked_symbol < SymbolType, RankType > > & dest, unsigned & readIndex ) { + unsigned root = readIndex --; + unsigned rank = ( unsigned ) src [ root ].getRank ( ); + + for ( unsigned i = 0; i < rank; ++ i ) + postfixToPrefixInt ( src, dest, readIndex ); + + dest.push_back ( src [ root ] ); +} + +template < class SymbolType, class RankType > +ext::vector < common::ranked_symbol < SymbolType, RankType > > TreeAuxiliary::treeToPrefix ( const ext::tree < common::ranked_symbol < SymbolType, RankType > > & tree ) { + ext::vector < common::ranked_symbol < SymbolType, RankType > > res; + + for ( typename ext::tree < common::ranked_symbol < SymbolType, RankType > >::const_prefix_iterator iter = tree.prefix_begin ( ); iter != tree.prefix_end ( ); ++iter ) + res.push_back ( * iter ); + + return res; +} + +template < class SymbolType > +ext::vector < SymbolType > TreeAuxiliary::treeToPrefix ( const ext::tree < SymbolType > & tree, const SymbolType & bar ) { + ext::vector < SymbolType > res; + + for ( typename ext::tree < SymbolType >::const_structure_iterator iter = tree.structure_begin ( ); iter != tree.structure_end ( ); ++iter ) + if ( iter.getVirtual ( ) ) + res.push_back ( bar ); + else + res.push_back ( * iter ); + + return res; +} + +template < class SymbolType, class RankType > +ext::vector < common::ranked_symbol < SymbolType, RankType > > TreeAuxiliary::treeToPrefix ( const ext::tree < common::ranked_symbol < SymbolType, RankType > > & tree, const SymbolType & barBase ) { + ext::vector < common::ranked_symbol < SymbolType, RankType > > res; + + for ( typename ext::tree < common::ranked_symbol < SymbolType, RankType > >::const_structure_iterator iter = tree.structure_begin ( ); iter != tree.structure_end ( ); ++iter ) + if ( iter.getVirtual ( ) ) + res.push_back ( common::ranked_symbol < SymbolType, RankType > ( barBase, iter->getRank ( ) ) ); + else + res.push_back ( * iter ); + + return res; +} + +template < class SymbolType, class RankType > +ext::vector < common::ranked_symbol < SymbolType, RankType > > TreeAuxiliary::treeToPrefix ( const ext::tree < common::ranked_symbol < SymbolType, RankType > > & tree, const common::ranked_symbol < SymbolType, RankType > & subtreeWildcard, const SymbolType & barBase, const common::ranked_symbol < SymbolType, RankType > & variablesBar ) { + ext::vector < common::ranked_symbol < SymbolType, RankType > > res; + + for ( typename ext::tree < common::ranked_symbol < SymbolType, RankType > >::const_structure_iterator iter = tree.structure_begin ( ); iter != tree.structure_end ( ); ++iter ) + if ( iter.getVirtual ( ) ) + if ( ( * iter == subtreeWildcard ) ) + res.push_back ( variablesBar ); + else + res.push_back ( common::ranked_symbol < SymbolType, RankType > ( barBase, iter->getRank ( ) ) ); + else + res.push_back ( * iter ); + + return res; +} + +template < class SymbolType, class RankType > +ext::vector < common::ranked_symbol < SymbolType, RankType > > TreeAuxiliary::treeToPrefix ( const ext::tree < common::ranked_symbol < SymbolType, RankType > > & tree, const common::ranked_symbol < SymbolType, RankType > & subtreeWildcard, const ext::set < common::ranked_symbol < SymbolType, RankType > > & nonlinearVariables, const SymbolType & barBase, const common::ranked_symbol < SymbolType, RankType > & variablesBar ) { + ext::vector < common::ranked_symbol < SymbolType, RankType > > res; + + for ( typename ext::tree < common::ranked_symbol < SymbolType, RankType > >::const_structure_iterator iter = tree.structure_begin ( ); iter != tree.structure_end ( ); ++iter ) + if ( iter.getVirtual ( ) ) + if ( ( * iter == subtreeWildcard ) || nonlinearVariables.count ( * iter ) ) + res.push_back ( variablesBar ); + else + res.push_back ( common::ranked_symbol < SymbolType, RankType > ( barBase, iter->getRank ( ) ) ); + else + res.push_back ( * iter ); + + return res; +} + +template < class SymbolType, class RankType > +ext::vector < common::ranked_symbol < SymbolType, RankType > > TreeAuxiliary::treeToPostfix ( const ext::tree < common::ranked_symbol < SymbolType, RankType > > & tree ) { + ext::vector < common::ranked_symbol < SymbolType, RankType > > res; + + for ( typename ext::tree < common::ranked_symbol < SymbolType, RankType > >::const_postfix_iterator iter = tree.postfix_begin ( ); iter != tree.postfix_end ( ); ++iter ) + res.push_back ( * iter ); + + return res; +} + } /* namespace tree */ #endif /* TREE_AUXILIARY_H_ */ diff --git a/alib2data/src/tree/ranked/PostfixRankedTree.h b/alib2data/src/tree/ranked/PostfixRankedTree.h index 0420553fea..439a972808 100644 --- a/alib2data/src/tree/ranked/PostfixRankedTree.h +++ b/alib2data/src/tree/ranked/PostfixRankedTree.h @@ -26,6 +26,7 @@ #include "../TreeBase.h" #include "../common/TreeFromXMLParser.h" #include "../common/TreeToXMLComposer.h" +#include "../common/TreeAuxiliary.h" #include <tree/common/TreeNormalize.h> #include <core/normalize.hpp> @@ -42,8 +43,6 @@ template < class SymbolType, class RankType > class PostfixRankedTree final : public TreeBase, public core::Components < PostfixRankedTree < SymbolType, RankType >, ext::set < common::ranked_symbol < SymbolType, RankType > >, component::Set, GeneralAlphabet > { ext::vector < common::ranked_symbol < SymbolType, RankType > > m_Data; - static ext::vector < common::ranked_symbol < SymbolType, RankType > > toPostfixRanked ( const ext::tree < common::ranked_symbol < SymbolType, RankType > > & tree ); - public: explicit PostfixRankedTree ( ext::set < common::ranked_symbol < SymbolType, RankType > > alphabet, ext::vector < common::ranked_symbol < SymbolType, RankType > > data ); explicit PostfixRankedTree ( ext::vector < common::ranked_symbol < SymbolType, RankType > > data ); @@ -123,17 +122,7 @@ PostfixRankedTree < SymbolType, RankType >::PostfixRankedTree ( ext::vector < co } template < class SymbolType, class RankType > -PostfixRankedTree < SymbolType, RankType >::PostfixRankedTree ( const RankedTree < SymbolType, RankType > & tree ) : PostfixRankedTree ( tree.getAlphabet ( ), toPostfixRanked ( tree.getContent ( ) ) ) { -} - -template < class SymbolType, class RankType > -ext::vector < common::ranked_symbol < SymbolType, RankType > > PostfixRankedTree < SymbolType, RankType >::toPostfixRanked ( const ext::tree < common::ranked_symbol < SymbolType, RankType > > & tree ) { - ext::vector < common::ranked_symbol < SymbolType, RankType > > res; - - for ( typename ext::tree < common::ranked_symbol < SymbolType, RankType > >::const_postfix_iterator iter = tree.postfix_begin ( ); iter != tree.postfix_end ( ); ++iter ) - res.push_back ( * iter ); - - return res; +PostfixRankedTree < SymbolType, RankType >::PostfixRankedTree ( const RankedTree < SymbolType, RankType > & tree ) : PostfixRankedTree ( tree.getAlphabet ( ), TreeAuxiliary::treeToPostfix ( tree.getContent ( ) ) ) { } template < class SymbolType, class RankType > diff --git a/alib2data/src/tree/ranked/PrefixRankedBarNonlinearPattern.h b/alib2data/src/tree/ranked/PrefixRankedBarNonlinearPattern.h index 0d68906383..b266c2b997 100644 --- a/alib2data/src/tree/ranked/PrefixRankedBarNonlinearPattern.h +++ b/alib2data/src/tree/ranked/PrefixRankedBarNonlinearPattern.h @@ -51,8 +51,6 @@ template < class SymbolType, class RankType > class PrefixRankedBarNonlinearPattern final : public TreeBase, public core::Components < PrefixRankedBarNonlinearPattern < SymbolType, RankType >, ext::set < common::ranked_symbol < SymbolType, RankType > >, component::Set, std::tuple < GeneralAlphabet, NonlinearAlphabet, BarSymbols >, common::ranked_symbol < SymbolType, RankType >, component::Value, std::tuple < SubtreeWildcard, VariablesBarSymbol > > { ext::vector < common::ranked_symbol < SymbolType, RankType > > m_Data; - static ext::vector < common::ranked_symbol < SymbolType, RankType > > toPrefixRankedBar ( const ext::tree < common::ranked_symbol < SymbolType, RankType > > & node, const common::ranked_symbol < SymbolType, RankType > & subtreeWildcard, const ext::set < common::ranked_symbol < SymbolType, RankType > > & nonlinearVariables, const SymbolType & barBase, const common::ranked_symbol < SymbolType, RankType > & variablesBar ); - public: explicit PrefixRankedBarNonlinearPattern ( ext::set < common::ranked_symbol < SymbolType, RankType > > bars, common::ranked_symbol < SymbolType, RankType > variablesBar, common::ranked_symbol < SymbolType, RankType > subtreeWildcard, ext::set < common::ranked_symbol < SymbolType, RankType > > nonlinearVariables, ext::set < common::ranked_symbol < SymbolType, RankType > > alphabet, ext::vector < common::ranked_symbol < SymbolType, RankType > > data ); explicit PrefixRankedBarNonlinearPattern ( ext::set < common::ranked_symbol < SymbolType, RankType > > bars, common::ranked_symbol < SymbolType, RankType > variablesBar, common::ranked_symbol < SymbolType, RankType > subtreeWildcard, ext::set < common::ranked_symbol < SymbolType, RankType > > nonlinearVariables, ext::vector < common::ranked_symbol < SymbolType, RankType > > data ); @@ -184,15 +182,15 @@ PrefixRankedBarNonlinearPattern < SymbolType, RankType >::PrefixRankedBarNonline } template < class SymbolType, class RankType > -PrefixRankedBarNonlinearPattern < SymbolType, RankType >::PrefixRankedBarNonlinearPattern ( SymbolType barBase, common::ranked_symbol < SymbolType, RankType > variablesBar, const RankedTree < SymbolType, RankType > & tree ) : PrefixRankedBarNonlinearPattern ( TreeAuxiliary::computeBars ( tree.getAlphabet ( ), barBase ) + ext::set < common::ranked_symbol < SymbolType, RankType > > { variablesBar }, variablesBar, alphabet::SubtreeWildcardSymbol::instance < common::ranked_symbol < SymbolType, RankType > > ( ), { }, tree.getAlphabet ( ) + TreeAuxiliary::computeBars ( tree.getAlphabet ( ), barBase ) + ext::set < common::ranked_symbol < SymbolType, RankType > > { variablesBar, alphabet::SubtreeWildcardSymbol::instance < common::ranked_symbol < SymbolType, RankType > > ( ) }, toPrefixRankedBar ( tree.getContent ( ), alphabet::SubtreeWildcardSymbol::instance < common::ranked_symbol < SymbolType, RankType > > ( ), { }, barBase, variablesBar ) ) { +PrefixRankedBarNonlinearPattern < SymbolType, RankType >::PrefixRankedBarNonlinearPattern ( SymbolType barBase, common::ranked_symbol < SymbolType, RankType > variablesBar, const RankedTree < SymbolType, RankType > & tree ) : PrefixRankedBarNonlinearPattern ( TreeAuxiliary::computeBars ( tree.getAlphabet ( ), barBase ) + ext::set < common::ranked_symbol < SymbolType, RankType > > { variablesBar }, variablesBar, alphabet::SubtreeWildcardSymbol::instance < common::ranked_symbol < SymbolType, RankType > > ( ), { }, tree.getAlphabet ( ) + TreeAuxiliary::computeBars ( tree.getAlphabet ( ), barBase ) + ext::set < common::ranked_symbol < SymbolType, RankType > > { variablesBar, alphabet::SubtreeWildcardSymbol::instance < common::ranked_symbol < SymbolType, RankType > > ( ) }, TreeAuxiliary::treeToPrefix ( tree.getContent ( ), alphabet::SubtreeWildcardSymbol::instance < common::ranked_symbol < SymbolType, RankType > > ( ), { }, barBase, variablesBar ) ) { } template < class SymbolType, class RankType > -PrefixRankedBarNonlinearPattern < SymbolType, RankType >::PrefixRankedBarNonlinearPattern ( SymbolType barBase, common::ranked_symbol < SymbolType, RankType > variablesBar, const RankedPattern < SymbolType, RankType > & tree ) : PrefixRankedBarNonlinearPattern ( TreeAuxiliary::computeBars ( tree.getAlphabet ( ), barBase ) + ext::set < common::ranked_symbol < SymbolType, RankType > > { variablesBar }, variablesBar, tree.getSubtreeWildcard ( ), { }, tree.getAlphabet ( ) + TreeAuxiliary::computeBars ( tree.getAlphabet ( ), barBase ) + ext::set < common::ranked_symbol < SymbolType, RankType > > { variablesBar, tree.getSubtreeWildcard ( ) }, toPrefixRankedBar ( tree.getContent ( ), tree.getSubtreeWildcard ( ), { }, barBase, variablesBar ) ) { +PrefixRankedBarNonlinearPattern < SymbolType, RankType >::PrefixRankedBarNonlinearPattern ( SymbolType barBase, common::ranked_symbol < SymbolType, RankType > variablesBar, const RankedPattern < SymbolType, RankType > & tree ) : PrefixRankedBarNonlinearPattern ( TreeAuxiliary::computeBars ( tree.getAlphabet ( ), barBase ) + ext::set < common::ranked_symbol < SymbolType, RankType > > { variablesBar }, variablesBar, tree.getSubtreeWildcard ( ), { }, tree.getAlphabet ( ) + TreeAuxiliary::computeBars ( tree.getAlphabet ( ), barBase ) + ext::set < common::ranked_symbol < SymbolType, RankType > > { variablesBar, tree.getSubtreeWildcard ( ) }, TreeAuxiliary::treeToPrefix ( tree.getContent ( ), tree.getSubtreeWildcard ( ), { }, barBase, variablesBar ) ) { } template < class SymbolType, class RankType > -PrefixRankedBarNonlinearPattern < SymbolType, RankType >::PrefixRankedBarNonlinearPattern ( SymbolType barBase, common::ranked_symbol < SymbolType, RankType > variablesBar, const RankedNonlinearPattern < SymbolType, RankType > & tree ) : PrefixRankedBarNonlinearPattern ( TreeAuxiliary::computeBars ( tree.getAlphabet ( ), barBase ) + ext::set < common::ranked_symbol < SymbolType, RankType > > { variablesBar }, variablesBar, tree.getSubtreeWildcard ( ), tree.getNonlinearVariables ( ), tree.getAlphabet ( ) + TreeAuxiliary::computeBars ( tree.getAlphabet ( ), barBase ) + ext::set < common::ranked_symbol < SymbolType, RankType > > { variablesBar, tree.getSubtreeWildcard ( ) } + tree.getNonlinearVariables ( ), toPrefixRankedBar ( tree.getContent ( ), tree.getSubtreeWildcard ( ), tree.getNonlinearVariables ( ), barBase, variablesBar ) ) { +PrefixRankedBarNonlinearPattern < SymbolType, RankType >::PrefixRankedBarNonlinearPattern ( SymbolType barBase, common::ranked_symbol < SymbolType, RankType > variablesBar, const RankedNonlinearPattern < SymbolType, RankType > & tree ) : PrefixRankedBarNonlinearPattern ( TreeAuxiliary::computeBars ( tree.getAlphabet ( ), barBase ) + ext::set < common::ranked_symbol < SymbolType, RankType > > { variablesBar }, variablesBar, tree.getSubtreeWildcard ( ), tree.getNonlinearVariables ( ), tree.getAlphabet ( ) + TreeAuxiliary::computeBars ( tree.getAlphabet ( ), barBase ) + ext::set < common::ranked_symbol < SymbolType, RankType > > { variablesBar, tree.getSubtreeWildcard ( ) } + tree.getNonlinearVariables ( ), TreeAuxiliary::treeToPrefix ( tree.getContent ( ), tree.getSubtreeWildcard ( ), tree.getNonlinearVariables ( ), barBase, variablesBar ) ) { } template < class SymbolType, class RankType > @@ -215,22 +213,6 @@ template < class SymbolType, class RankType > PrefixRankedBarNonlinearPattern < SymbolType, RankType >::PrefixRankedBarNonlinearPattern ( const RankedNonlinearPattern < SymbolType, RankType > & tree ) : PrefixRankedBarNonlinearPattern ( alphabet::BarSymbol::instance < SymbolType > ( ), alphabet::VariablesBarSymbol::instance < common::ranked_symbol < SymbolType, RankType > > ( ), tree ) { } -template < class SymbolType, class RankType > -ext::vector < common::ranked_symbol < SymbolType, RankType > > PrefixRankedBarNonlinearPattern < SymbolType, RankType >::toPrefixRankedBar ( const ext::tree < common::ranked_symbol < SymbolType, RankType > > & tree, const common::ranked_symbol < SymbolType, RankType > & subtreeWildcard, const ext::set < common::ranked_symbol < SymbolType, RankType > > & nonlinearVariables, const SymbolType & barBase, const common::ranked_symbol < SymbolType, RankType > & variablesBar ) { - ext::vector < common::ranked_symbol < SymbolType, RankType > > res; - - for ( typename ext::tree < common::ranked_symbol < SymbolType, RankType > >::const_structure_iterator iter = tree.structure_begin ( ); iter != tree.structure_end ( ); ++iter ) - if ( iter.getVirtual ( ) ) - if ( ( * iter == subtreeWildcard ) || nonlinearVariables.count ( * iter ) ) - res.push_back ( variablesBar ); - else - res.push_back ( common::ranked_symbol < SymbolType, RankType > ( barBase, iter->getRank ( ) ) ); - else - res.push_back ( * iter ); - - return res; -} - template < class SymbolType, class RankType > TreeBase * PrefixRankedBarNonlinearPattern < SymbolType, RankType >::clone ( ) const { return new PrefixRankedBarNonlinearPattern ( * this ); diff --git a/alib2data/src/tree/ranked/PrefixRankedBarPattern.h b/alib2data/src/tree/ranked/PrefixRankedBarPattern.h index 28880c2804..f3ae758f06 100644 --- a/alib2data/src/tree/ranked/PrefixRankedBarPattern.h +++ b/alib2data/src/tree/ranked/PrefixRankedBarPattern.h @@ -50,8 +50,6 @@ template < class SymbolType, class RankType > class PrefixRankedBarPattern final : public TreeBase, public core::Components < PrefixRankedBarPattern < SymbolType, RankType >, ext::set < common::ranked_symbol < SymbolType, RankType > >, component::Set, std::tuple < GeneralAlphabet, BarSymbols >, common::ranked_symbol < SymbolType, RankType >, component::Value, std::tuple < SubtreeWildcard, VariablesBarSymbol > > { ext::vector < common::ranked_symbol < SymbolType, RankType > > m_Data; - static ext::vector < common::ranked_symbol < SymbolType, RankType > > toPrefixRankedBar ( const ext::tree < common::ranked_symbol < SymbolType, RankType > > & node, const common::ranked_symbol < SymbolType, RankType > & subtreeWildcard, const SymbolType & barBase, const common::ranked_symbol < SymbolType, RankType > & variablesBar ); - public: explicit PrefixRankedBarPattern ( ext::set < common::ranked_symbol < SymbolType, RankType > > bar, common::ranked_symbol < SymbolType, RankType > variablesBar, common::ranked_symbol < SymbolType, RankType > subtreeWildcard, ext::set < common::ranked_symbol < SymbolType, RankType > > alphabet, ext::vector < common::ranked_symbol < SymbolType, RankType > > data ); explicit PrefixRankedBarPattern ( ext::set < common::ranked_symbol < SymbolType, RankType > > bar, common::ranked_symbol < SymbolType, RankType > variablesBar, common::ranked_symbol < SymbolType, RankType > subtreeWildcard, ext::vector < common::ranked_symbol < SymbolType, RankType > > data ); @@ -162,7 +160,7 @@ PrefixRankedBarPattern < SymbolType, RankType >::PrefixRankedBarPattern ( ext::s } template < class SymbolType, class RankType > -PrefixRankedBarPattern < SymbolType, RankType >::PrefixRankedBarPattern ( SymbolType barBase, common::ranked_symbol < SymbolType, RankType > variablesBar, const RankedPattern < SymbolType, RankType > & tree ) : PrefixRankedBarPattern ( TreeAuxiliary::computeBars ( tree.getAlphabet ( ), barBase ) + ext::set < common::ranked_symbol < SymbolType, RankType > > { variablesBar }, variablesBar, tree.getSubtreeWildcard ( ), tree.getAlphabet ( ) + TreeAuxiliary::computeBars ( tree.getAlphabet ( ), barBase ) + ext::set < common::ranked_symbol < SymbolType, RankType > > { variablesBar, tree.getSubtreeWildcard ( ) }, toPrefixRankedBar ( tree.getContent ( ), tree.getSubtreeWildcard ( ), barBase, variablesBar ) ) { +PrefixRankedBarPattern < SymbolType, RankType >::PrefixRankedBarPattern ( SymbolType barBase, common::ranked_symbol < SymbolType, RankType > variablesBar, const RankedPattern < SymbolType, RankType > & tree ) : PrefixRankedBarPattern ( TreeAuxiliary::computeBars ( tree.getAlphabet ( ), barBase ) + ext::set < common::ranked_symbol < SymbolType, RankType > > { variablesBar }, variablesBar, tree.getSubtreeWildcard ( ), tree.getAlphabet ( ) + TreeAuxiliary::computeBars ( tree.getAlphabet ( ), barBase ) + ext::set < common::ranked_symbol < SymbolType, RankType > > { variablesBar, tree.getSubtreeWildcard ( ) }, TreeAuxiliary::treeToPrefix ( tree.getContent ( ), tree.getSubtreeWildcard ( ), barBase, variablesBar ) ) { } template < class SymbolType, class RankType > @@ -173,22 +171,6 @@ template < class SymbolType, class RankType > PrefixRankedBarPattern < SymbolType, RankType >::PrefixRankedBarPattern ( const RankedPattern < SymbolType, RankType > & tree ) : PrefixRankedBarPattern ( alphabet::BarSymbol::instance < SymbolType > ( ), alphabet::VariablesBarSymbol::instance < common::ranked_symbol < SymbolType, RankType > > ( ), tree ) { } -template < class SymbolType, class RankType > -ext::vector < common::ranked_symbol < SymbolType, RankType > > PrefixRankedBarPattern < SymbolType, RankType >::toPrefixRankedBar ( const ext::tree < common::ranked_symbol < SymbolType, RankType > > & tree, const common::ranked_symbol < SymbolType, RankType > & subtreeWildcard, const SymbolType & barBase, const common::ranked_symbol < SymbolType, RankType > & variablesBar ) { - ext::vector < common::ranked_symbol < SymbolType, RankType > > res; - - for ( typename ext::tree < common::ranked_symbol < SymbolType, RankType > >::const_structure_iterator iter = tree.structure_begin ( ); iter != tree.structure_end ( ); ++iter ) - if ( iter.getVirtual ( ) ) - if ( ( * iter == subtreeWildcard ) ) - res.push_back ( variablesBar ); - else - res.push_back ( common::ranked_symbol < SymbolType, RankType > ( barBase, iter->getRank ( ) ) ); - else - res.push_back ( * iter ); - - return res; -} - template < class SymbolType, class RankType > TreeBase * PrefixRankedBarPattern < SymbolType, RankType >::clone ( ) const { return new PrefixRankedBarPattern ( * this ); diff --git a/alib2data/src/tree/ranked/PrefixRankedBarTree.h b/alib2data/src/tree/ranked/PrefixRankedBarTree.h index 723a0026b5..568a4f621d 100644 --- a/alib2data/src/tree/ranked/PrefixRankedBarTree.h +++ b/alib2data/src/tree/ranked/PrefixRankedBarTree.h @@ -46,8 +46,6 @@ template < class SymbolType, class RankType > class PrefixRankedBarTree final : public TreeBase, public core::Components < PrefixRankedBarTree < SymbolType, RankType >, ext::set < common::ranked_symbol < SymbolType, RankType > >, component::Set, std::tuple < GeneralAlphabet, BarSymbols > > { ext::vector < common::ranked_symbol < SymbolType, RankType > > m_Data; - static ext::vector < common::ranked_symbol < SymbolType, RankType > > toPrefixRankedBar ( const ext::tree < common::ranked_symbol < SymbolType, RankType > > & node, const SymbolType & barBase ); - public: explicit PrefixRankedBarTree ( ext::set < common::ranked_symbol < SymbolType, RankType > > bars, ext::set < common::ranked_symbol < SymbolType, RankType > > alphabet, ext::vector < common::ranked_symbol < SymbolType, RankType > > data ); explicit PrefixRankedBarTree ( ext::set < common::ranked_symbol < SymbolType, RankType > > bars, ext::vector < common::ranked_symbol < SymbolType, RankType > > data ); @@ -140,26 +138,13 @@ PrefixRankedBarTree < SymbolType, RankType >::PrefixRankedBarTree ( ext::set < c } template < class SymbolType, class RankType > -PrefixRankedBarTree < SymbolType, RankType >::PrefixRankedBarTree ( SymbolType barBase, const RankedTree < SymbolType, RankType > & tree ) : PrefixRankedBarTree ( TreeAuxiliary::computeBars ( tree.getAlphabet ( ), barBase ), tree.getAlphabet ( ) + TreeAuxiliary::computeBars ( tree.getAlphabet ( ), barBase ), toPrefixRankedBar ( tree.getContent ( ), barBase ) ) { +PrefixRankedBarTree < SymbolType, RankType >::PrefixRankedBarTree ( SymbolType barBase, const RankedTree < SymbolType, RankType > & tree ) : PrefixRankedBarTree ( TreeAuxiliary::computeBars ( tree.getAlphabet ( ), barBase ), tree.getAlphabet ( ) + TreeAuxiliary::computeBars ( tree.getAlphabet ( ), barBase ), TreeAuxiliary::treeToPrefix ( tree.getContent ( ), barBase ) ) { } template < class SymbolType, class RankType > PrefixRankedBarTree < SymbolType, RankType >::PrefixRankedBarTree ( const RankedTree < > & tree ) : PrefixRankedBarTree ( alphabet::BarSymbol::instance < SymbolType > ( ), tree ) { } -template < class SymbolType, class RankType > -ext::vector < common::ranked_symbol < SymbolType, RankType > > PrefixRankedBarTree < SymbolType, RankType >::toPrefixRankedBar ( const ext::tree < common::ranked_symbol < SymbolType, RankType > > & tree, const SymbolType & barBase ) { - ext::vector < common::ranked_symbol < SymbolType, RankType > > res; - - for ( typename ext::tree < common::ranked_symbol < SymbolType, RankType > >::const_structure_iterator iter = tree.structure_begin ( ); iter != tree.structure_end ( ); ++iter ) - if ( iter.getVirtual ( ) ) - res.push_back ( common::ranked_symbol < SymbolType, RankType > ( barBase, iter->getRank ( ) ) ); - else - res.push_back ( * iter ); - - return res; -} - template < class SymbolType, class RankType > TreeBase * PrefixRankedBarTree < SymbolType, RankType >::clone ( ) const { return new PrefixRankedBarTree ( * this ); diff --git a/alib2data/src/tree/ranked/PrefixRankedNonlinearPattern.h b/alib2data/src/tree/ranked/PrefixRankedNonlinearPattern.h index 12432cb30c..5069b8c873 100644 --- a/alib2data/src/tree/ranked/PrefixRankedNonlinearPattern.h +++ b/alib2data/src/tree/ranked/PrefixRankedNonlinearPattern.h @@ -26,6 +26,7 @@ #include "../TreeBase.h" #include "../common/TreeFromXMLParser.h" #include "../common/TreeToXMLComposer.h" +#include "../common/TreeAuxiliary.h" #include <tree/common/TreeNormalize.h> #include <alphabet/SubtreeWildcardSymbol.h> @@ -46,8 +47,6 @@ template < class SymbolType, class RankType > class PrefixRankedNonlinearPattern final : public TreeBase, public core::Components < PrefixRankedNonlinearPattern < SymbolType, RankType >, ext::set < common::ranked_symbol < SymbolType, RankType > >, component::Set, std::tuple < GeneralAlphabet, NonlinearAlphabet >, common::ranked_symbol < SymbolType, RankType >, component::Value, SubtreeWildcard > { ext::vector < common::ranked_symbol < SymbolType, RankType > > m_Data; - static ext::vector < common::ranked_symbol < SymbolType, RankType > > toPrefixRanked ( const ext::tree < common::ranked_symbol < SymbolType, RankType > > & tree ); - public: explicit PrefixRankedNonlinearPattern ( common::ranked_symbol < SymbolType, RankType > subtreeWildcard, ext::set < common::ranked_symbol < SymbolType, RankType > > nonlinearVariables, ext::set < common::ranked_symbol < SymbolType, RankType > > alphabet, ext::vector < common::ranked_symbol < SymbolType, RankType > > data ); explicit PrefixRankedNonlinearPattern ( common::ranked_symbol < SymbolType, RankType > subtreeWildcard, ext::set < common::ranked_symbol < SymbolType, RankType > > nonlinearVariables, ext::vector < common::ranked_symbol < SymbolType, RankType > > data ); @@ -164,25 +163,15 @@ PrefixRankedNonlinearPattern < SymbolType, RankType >::PrefixRankedNonlinearPatt } template < class SymbolType, class RankType > -PrefixRankedNonlinearPattern < SymbolType, RankType >::PrefixRankedNonlinearPattern ( const RankedTree < SymbolType, RankType > & tree ) : PrefixRankedNonlinearPattern ( alphabet::SubtreeWildcardSymbol::instance < common::ranked_symbol < SymbolType, RankType > > ( ), { }, tree.getAlphabet ( ), toPrefixRanked ( tree.getContent ( ) ) ) { -} - -template < class SymbolType, class RankType > -PrefixRankedNonlinearPattern < SymbolType, RankType >::PrefixRankedNonlinearPattern ( const RankedPattern < SymbolType, RankType > & tree ) : PrefixRankedNonlinearPattern ( tree.getSubtreeWildcard ( ), { }, tree.getAlphabet ( ), toPrefixRanked ( tree.getContent ( ) ) ) { +PrefixRankedNonlinearPattern < SymbolType, RankType >::PrefixRankedNonlinearPattern ( const RankedTree < SymbolType, RankType > & tree ) : PrefixRankedNonlinearPattern ( alphabet::SubtreeWildcardSymbol::instance < common::ranked_symbol < SymbolType, RankType > > ( ), { }, tree.getAlphabet ( ), TreeAuxiliary::treeToPrefix ( tree.getContent ( ) ) ) { } template < class SymbolType, class RankType > -PrefixRankedNonlinearPattern < SymbolType, RankType >::PrefixRankedNonlinearPattern ( const RankedNonlinearPattern < SymbolType, RankType > & tree ) : PrefixRankedNonlinearPattern ( tree.getSubtreeWildcard ( ), tree.getNonlinearVariables ( ), tree.getAlphabet ( ), toPrefixRanked ( tree.getContent ( ) ) ) { +PrefixRankedNonlinearPattern < SymbolType, RankType >::PrefixRankedNonlinearPattern ( const RankedPattern < SymbolType, RankType > & tree ) : PrefixRankedNonlinearPattern ( tree.getSubtreeWildcard ( ), { }, tree.getAlphabet ( ), TreeAuxiliary::treeToPrefix ( tree.getContent ( ) ) ) { } template < class SymbolType, class RankType > -ext::vector < common::ranked_symbol < SymbolType, RankType > > PrefixRankedNonlinearPattern < SymbolType, RankType >::toPrefixRanked ( const ext::tree < common::ranked_symbol < SymbolType, RankType > > & tree ) { - ext::vector < common::ranked_symbol < SymbolType, RankType > > res; - - for ( typename ext::tree < common::ranked_symbol < SymbolType, RankType > >::const_prefix_iterator iter = tree.prefix_begin ( ); iter != tree.prefix_end ( ); ++iter ) - res.push_back ( * iter ); - - return res; +PrefixRankedNonlinearPattern < SymbolType, RankType >::PrefixRankedNonlinearPattern ( const RankedNonlinearPattern < SymbolType, RankType > & tree ) : PrefixRankedNonlinearPattern ( tree.getSubtreeWildcard ( ), tree.getNonlinearVariables ( ), tree.getAlphabet ( ), TreeAuxiliary::treeToPrefix ( tree.getContent ( ) ) ) { } template < class SymbolType, class RankType > diff --git a/alib2data/src/tree/ranked/PrefixRankedPattern.h b/alib2data/src/tree/ranked/PrefixRankedPattern.h index 3c7ac165f9..7ba8a58fdc 100644 --- a/alib2data/src/tree/ranked/PrefixRankedPattern.h +++ b/alib2data/src/tree/ranked/PrefixRankedPattern.h @@ -26,6 +26,7 @@ #include "../TreeBase.h" #include "../common/TreeFromXMLParser.h" #include "../common/TreeToXMLComposer.h" +#include "../common/TreeAuxiliary.h" #include <tree/common/TreeNormalize.h> #include <alphabet/SubtreeWildcardSymbol.h> @@ -45,8 +46,6 @@ template < class SymbolType, class RankType > class PrefixRankedPattern final : public TreeBase, public core::Components < PrefixRankedPattern < SymbolType, RankType >, ext::set < common::ranked_symbol < SymbolType, RankType > >, component::Set, GeneralAlphabet, common::ranked_symbol < SymbolType, RankType >, component::Value, SubtreeWildcard > { ext::vector < common::ranked_symbol < SymbolType, RankType > > m_Data; - static ext::vector < common::ranked_symbol < SymbolType, RankType > > toPrefixRanked ( const ext::tree < common::ranked_symbol < SymbolType, RankType > > & tree ); - public: explicit PrefixRankedPattern ( common::ranked_symbol < SymbolType, RankType > subtreeWildcard, ext::set < common::ranked_symbol < SymbolType, RankType > > alphabet, ext::vector < common::ranked_symbol < SymbolType, RankType > > data ); explicit PrefixRankedPattern ( common::ranked_symbol < SymbolType, RankType > subtreeWildcard, ext::vector < common::ranked_symbol < SymbolType, RankType > > data ); @@ -140,17 +139,7 @@ PrefixRankedPattern < SymbolType, RankType >::PrefixRankedPattern ( const Prefix } template < class SymbolType, class RankType > -PrefixRankedPattern < SymbolType, RankType >::PrefixRankedPattern ( const RankedPattern < SymbolType, RankType > & tree ) : PrefixRankedPattern ( tree.getSubtreeWildcard ( ), tree.getAlphabet ( ), toPrefixRanked ( tree.getContent ( ) ) ) { -} - -template < class SymbolType, class RankType > -ext::vector < common::ranked_symbol < SymbolType, RankType > > PrefixRankedPattern < SymbolType, RankType >::toPrefixRanked ( const ext::tree < common::ranked_symbol < SymbolType, RankType > > & tree ) { - ext::vector < common::ranked_symbol < SymbolType, RankType > > res; - - for ( typename ext::tree < common::ranked_symbol < SymbolType, RankType > >::const_prefix_iterator iter = tree.prefix_begin ( ); iter != tree.prefix_end ( ); ++iter ) - res.push_back ( * iter ); - - return res; +PrefixRankedPattern < SymbolType, RankType >::PrefixRankedPattern ( const RankedPattern < SymbolType, RankType > & tree ) : PrefixRankedPattern ( tree.getSubtreeWildcard ( ), tree.getAlphabet ( ), TreeAuxiliary::treeToPrefix ( tree.getContent ( ) ) ) { } template < class SymbolType, class RankType > diff --git a/alib2data/src/tree/ranked/PrefixRankedTree.h b/alib2data/src/tree/ranked/PrefixRankedTree.h index 0462caf210..de36964358 100644 --- a/alib2data/src/tree/ranked/PrefixRankedTree.h +++ b/alib2data/src/tree/ranked/PrefixRankedTree.h @@ -42,10 +42,6 @@ template < class SymbolType, class RankType > class PrefixRankedTree final : public TreeBase, public core::Components < PrefixRankedTree < SymbolType, RankType >, ext::set < common::ranked_symbol < SymbolType, RankType > >, component::Set, GeneralAlphabet > { ext::vector < common::ranked_symbol < SymbolType, RankType > > m_Data; - static ext::vector < common::ranked_symbol < SymbolType, RankType > > toPrefixRanked ( const ext::tree < common::ranked_symbol < SymbolType, RankType > > & tree ); - - static ext::vector < common::ranked_symbol < SymbolType, RankType > > postfixToPrefixRanked ( const ext::vector < common::ranked_symbol < SymbolType, RankType > > & tree ); - public: explicit PrefixRankedTree ( ext::set < common::ranked_symbol < SymbolType, RankType > > alphabet, ext::vector < common::ranked_symbol < SymbolType, RankType > > data ); explicit PrefixRankedTree ( ext::vector < common::ranked_symbol < SymbolType, RankType > > data ); @@ -126,44 +122,11 @@ PrefixRankedTree < SymbolType, RankType >::PrefixRankedTree ( ext::vector < comm } template < class SymbolType, class RankType > -PrefixRankedTree < SymbolType, RankType >::PrefixRankedTree ( const RankedTree < SymbolType, RankType > & tree ) : PrefixRankedTree ( tree.getAlphabet ( ), toPrefixRanked ( tree.getContent ( ) ) ) { -} - -template < class SymbolType, class RankType > -PrefixRankedTree < SymbolType, RankType >::PrefixRankedTree ( const PostfixRankedTree < SymbolType, RankType > & other) : PrefixRankedTree ( postfixToPrefixRanked ( other.getContent ( ) ) ) { -} - -template < class SymbolType, class RankType > -ext::vector < common::ranked_symbol < SymbolType, RankType > > PrefixRankedTree < SymbolType, RankType >::postfixToPrefixRanked ( const ext::vector < common::ranked_symbol < SymbolType, RankType > > & tree ) { - ext::deque < ext::vector < common::ranked_symbol < SymbolType, RankType > > > stack; - - for ( const typename common::ranked_symbol < SymbolType, RankType > & symbol : tree ) { - ext::vector < common::ranked_symbol < SymbolType, RankType > > sub; - - sub.push_back ( symbol ); - - for ( unsigned i = ( unsigned ) symbol.getRank ( ); i > 0; -- i ) - sub.insert ( sub.end ( ), std::make_move_iterator ( stack [ stack.size ( ) - i ].begin ( ) ), std::make_move_iterator ( stack [ stack.size ( ) - i ].end ( ) ) ); - - for ( unsigned i = 0; i < ( unsigned ) symbol.getRank ( ); ++ i ) - stack.pop_back ( ); - - stack.push_back ( std::move ( sub ) ); - } - - std::cout << stack.back ( ) << std::endl; - - return std::move ( stack.back ( ) ); +PrefixRankedTree < SymbolType, RankType >::PrefixRankedTree ( const RankedTree < SymbolType, RankType > & tree ) : PrefixRankedTree ( tree.getAlphabet ( ), TreeAuxiliary::treeToPrefix ( tree.getContent ( ) ) ) { } template < class SymbolType, class RankType > -ext::vector < common::ranked_symbol < SymbolType, RankType > > PrefixRankedTree < SymbolType, RankType >::toPrefixRanked ( const ext::tree < common::ranked_symbol < SymbolType, RankType > > & tree ) { - ext::vector < common::ranked_symbol < SymbolType, RankType > > res; - - for ( typename ext::tree < common::ranked_symbol < SymbolType, RankType > >::const_prefix_iterator iter = tree.prefix_begin ( ); iter != tree.prefix_end ( ); ++iter ) - res.push_back ( * iter ); - - return res; +PrefixRankedTree < SymbolType, RankType >::PrefixRankedTree ( const PostfixRankedTree < SymbolType, RankType > & other) : PrefixRankedTree ( TreeAuxiliary::postfixToPrefix ( other.getContent ( ) ) ) { } template < class SymbolType, class RankType > diff --git a/alib2data/src/tree/ranked/RankedNonlinearPattern.h b/alib2data/src/tree/ranked/RankedNonlinearPattern.h index 7f33c38623..fd4e2b7666 100644 --- a/alib2data/src/tree/ranked/RankedNonlinearPattern.h +++ b/alib2data/src/tree/ranked/RankedNonlinearPattern.h @@ -161,7 +161,7 @@ RankedNonlinearPattern < SymbolType, RankType >::RankedNonlinearPattern ( common } template < class SymbolType, class RankType > -RankedNonlinearPattern < SymbolType, RankType >::RankedNonlinearPattern ( const UnrankedNonlinearPattern < SymbolType > & other ) : RankedNonlinearPattern ( common::ranked_symbol < SymbolType, RankType > ( other.getSubtreeWildcard ( ), 0 ), TreeAuxiliary::toRankedTree < SymbolType, RankType > ( other.getContent ( ) ) ) { +RankedNonlinearPattern < SymbolType, RankType >::RankedNonlinearPattern ( const UnrankedNonlinearPattern < SymbolType > & other ) : RankedNonlinearPattern ( common::ranked_symbol < SymbolType, RankType > ( other.getSubtreeWildcard ( ), 0 ), TreeAuxiliary::unrankedToRanked < SymbolType, RankType > ( other.getContent ( ) ) ) { } template < class SymbolType, class RankType > diff --git a/alib2data/src/tree/ranked/RankedPattern.h b/alib2data/src/tree/ranked/RankedPattern.h index 5e99433b05..660b1cfdc0 100644 --- a/alib2data/src/tree/ranked/RankedPattern.h +++ b/alib2data/src/tree/ranked/RankedPattern.h @@ -147,7 +147,7 @@ RankedPattern < SymbolType, RankType >::RankedPattern ( common::ranked_symbol < } template < class SymbolType, class RankType > -RankedPattern < SymbolType, RankType >::RankedPattern ( const UnrankedPattern < SymbolType > & other ) : RankedPattern ( common::ranked_symbol < SymbolType, RankType > ( other.getSubtreeWildcard ( ), RankType ( 0 ) ), TreeAuxiliary::toRankedTree < SymbolType, RankType > ( other.getContent ( ) ) ) { +RankedPattern < SymbolType, RankType >::RankedPattern ( const UnrankedPattern < SymbolType > & other ) : RankedPattern ( common::ranked_symbol < SymbolType, RankType > ( other.getSubtreeWildcard ( ), RankType ( 0 ) ), TreeAuxiliary::unrankedToRanked < SymbolType, RankType > ( other.getContent ( ) ) ) { } template < class SymbolType, class RankType > diff --git a/alib2data/src/tree/ranked/RankedTree.h b/alib2data/src/tree/ranked/RankedTree.h index ae1a1d02f5..a9591f3277 100644 --- a/alib2data/src/tree/ranked/RankedTree.h +++ b/alib2data/src/tree/ranked/RankedTree.h @@ -141,11 +141,11 @@ RankedTree < SymbolType, RankType >::RankedTree ( ext::tree < common::ranked_sym } template < class SymbolType, class RankType > -RankedTree < SymbolType, RankType >::RankedTree ( const UnrankedTree < SymbolType > & other ) : RankedTree ( TreeAuxiliary::toRankedTree < SymbolType, RankType > ( other.getContent ( ) ) ) { +RankedTree < SymbolType, RankType >::RankedTree ( const UnrankedTree < SymbolType > & other ) : RankedTree ( TreeAuxiliary::unrankedToRanked < SymbolType, RankType > ( other.getContent ( ) ) ) { } template < class SymbolType, class RankType > -RankedTree < SymbolType, RankType >::RankedTree ( const PostfixRankedTree < SymbolType, RankType > & other) : RankedTree ( TreeAuxiliary::postfixToRankedTree < SymbolType, RankType > ( other.getContent ( ) ) ) { +RankedTree < SymbolType, RankType >::RankedTree ( const PostfixRankedTree < SymbolType, RankType > & other) : RankedTree ( TreeAuxiliary::postfixToTree < SymbolType, RankType > ( other.getContent ( ) ) ) { } template < class SymbolType, class RankType > diff --git a/alib2data/src/tree/unranked/PrefixBarTree.h b/alib2data/src/tree/unranked/PrefixBarTree.h index 3ef42a9353..c5ae6f03ec 100644 --- a/alib2data/src/tree/unranked/PrefixBarTree.h +++ b/alib2data/src/tree/unranked/PrefixBarTree.h @@ -24,6 +24,7 @@ #include "../TreeException.h" #include "../common/TreeFromXMLParser.h" #include "../common/TreeToXMLComposer.h" +#include "../common/TreeAuxiliary.h" #include <tree/common/TreeNormalize.h> #include <alphabet/BarSymbol.h> @@ -42,8 +43,6 @@ template < class SymbolType > class PrefixBarTree final : public TreeBase, public core::Components < PrefixBarTree < SymbolType >, ext::set < SymbolType >, component::Set, GeneralAlphabet, SymbolType, component::Value, BarSymbol > { ext::vector < SymbolType > m_Data; - static ext::vector < SymbolType > toPrefixBar ( const ext::tree < SymbolType > & tree, const SymbolType & bar ); - public: explicit PrefixBarTree ( SymbolType bar, ext::set < SymbolType > alphabet, ext::vector < SymbolType > data ); explicit PrefixBarTree ( SymbolType bar, ext::vector < SymbolType > data ); @@ -132,26 +131,13 @@ PrefixBarTree < SymbolType >::PrefixBarTree ( SymbolType bar, ext::vector < Symb } template < class SymbolType > -PrefixBarTree < SymbolType >::PrefixBarTree ( SymbolType bar, const UnrankedTree < SymbolType > & tree ) : PrefixBarTree ( bar, tree.getAlphabet ( ) + ext::set < SymbolType > { bar }, toPrefixBar ( tree.getContent ( ), bar ) ) { +PrefixBarTree < SymbolType >::PrefixBarTree ( SymbolType bar, const UnrankedTree < SymbolType > & tree ) : PrefixBarTree ( bar, tree.getAlphabet ( ) + ext::set < SymbolType > { bar }, TreeAuxiliary::treeToPrefix ( tree.getContent ( ), bar ) ) { } template < class SymbolType > PrefixBarTree < SymbolType >::PrefixBarTree ( const UnrankedTree < SymbolType > & tree ) : PrefixBarTree ( alphabet::BarSymbol::instance < SymbolType > ( ), tree ) { } -template < class SymbolType > -ext::vector < SymbolType > PrefixBarTree < SymbolType >::toPrefixBar ( const ext::tree < SymbolType > & tree, const SymbolType & bar ) { - ext::vector < SymbolType > res; - - for ( typename ext::tree < SymbolType >::const_structure_iterator iter = tree.structure_begin ( ); iter != tree.structure_end ( ); ++iter ) - if ( iter.getVirtual ( ) ) - res.push_back ( bar ); - else - res.push_back ( * iter ); - - return res; -} - template < class SymbolType > TreeBase * PrefixBarTree < SymbolType >::clone ( ) const { return new PrefixBarTree ( * this ); diff --git a/alib2data/src/tree/unranked/UnrankedNonlinearPattern.h b/alib2data/src/tree/unranked/UnrankedNonlinearPattern.h index 5dfc434fd4..0392677faa 100644 --- a/alib2data/src/tree/unranked/UnrankedNonlinearPattern.h +++ b/alib2data/src/tree/unranked/UnrankedNonlinearPattern.h @@ -164,7 +164,7 @@ UnrankedNonlinearPattern < SymbolType >::UnrankedNonlinearPattern ( SymbolType s template < class SymbolType > template < class RankType > -UnrankedNonlinearPattern < SymbolType >::UnrankedNonlinearPattern ( const RankedNonlinearPattern < SymbolType, RankType > & other ) : UnrankedNonlinearPattern ( other.getSubtreeWildcard ( ).getSymbol ( ), TreeAuxiliary::unrankSymbols ( other.getAlphabet ( ) ), TreeAuxiliary::toUnrankedTree ( other.getContent ( ) ) ) { +UnrankedNonlinearPattern < SymbolType >::UnrankedNonlinearPattern ( const RankedNonlinearPattern < SymbolType, RankType > & other ) : UnrankedNonlinearPattern ( other.getSubtreeWildcard ( ).getSymbol ( ), TreeAuxiliary::unrankSymbols ( other.getAlphabet ( ) ), TreeAuxiliary::rankedToUnranked ( other.getContent ( ) ) ) { } template < class SymbolType > diff --git a/alib2data/src/tree/unranked/UnrankedPattern.h b/alib2data/src/tree/unranked/UnrankedPattern.h index a969b9b441..593f0a0388 100644 --- a/alib2data/src/tree/unranked/UnrankedPattern.h +++ b/alib2data/src/tree/unranked/UnrankedPattern.h @@ -144,7 +144,7 @@ UnrankedPattern < SymbolType >::UnrankedPattern ( SymbolType subtreeWildcard, ex template < class SymbolType > template < class RankType > -UnrankedPattern < SymbolType >::UnrankedPattern ( const RankedPattern < SymbolType, RankType > & other ) : UnrankedPattern ( other.getSubtreeWildcard ( ).getSymbol ( ), TreeAuxiliary::unrankSymbols ( other.getAlphabet ( ) ), TreeAuxiliary::toUnrankedTree ( other.getContent ( ) ) ) { +UnrankedPattern < SymbolType >::UnrankedPattern ( const RankedPattern < SymbolType, RankType > & other ) : UnrankedPattern ( other.getSubtreeWildcard ( ).getSymbol ( ), TreeAuxiliary::unrankSymbols ( other.getAlphabet ( ) ), TreeAuxiliary::rankedToUnranked ( other.getContent ( ) ) ) { } template < class SymbolType > diff --git a/alib2data/src/tree/unranked/UnrankedTree.h b/alib2data/src/tree/unranked/UnrankedTree.h index d240648917..489ee16930 100644 --- a/alib2data/src/tree/unranked/UnrankedTree.h +++ b/alib2data/src/tree/unranked/UnrankedTree.h @@ -135,7 +135,7 @@ UnrankedTree < SymbolType >::UnrankedTree ( ext::tree < SymbolType > pattern ) : template < class SymbolType > template < class RankType > -UnrankedTree < SymbolType >::UnrankedTree ( const RankedTree < SymbolType, RankType > & other ) : UnrankedTree ( TreeAuxiliary::unrankSymbols ( other.getAlphabet ( ) ), TreeAuxiliary::toUnrankedTree ( other.getContent ( ) ) ) { +UnrankedTree < SymbolType >::UnrankedTree ( const RankedTree < SymbolType, RankType > & other ) : UnrankedTree ( TreeAuxiliary::unrankSymbols ( other.getAlphabet ( ) ), TreeAuxiliary::rankedToUnranked ( other.getContent ( ) ) ) { } template < class SymbolType > -- GitLab