From 7aa3e592a061d21d164556e220a6752a5f7e50d5 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Sun, 5 Feb 2017 20:56:43 +0100 Subject: [PATCH] drop node alphabet from SuffixTrie --- .../stringology/indexing/SuffixTrieNaive.cpp | 4 +- .../stringology/indexing/SuffixTrieNaive.h | 13 +- .../stringology/query/SuffixTrieFactors.cpp | 2 +- .../src/stringology/query/SuffixTrieFactors.h | 27 +-- alib2data/src/indexes/SuffixTrie.cpp | 2 +- alib2data/src/indexes/SuffixTrie.h | 172 +++++++----------- aquery2/src/aquery.cpp | 2 +- astringology2/src/astringology.cpp | 2 +- 8 files changed, 89 insertions(+), 135 deletions(-) diff --git a/alib2algo/src/stringology/indexing/SuffixTrieNaive.cpp b/alib2algo/src/stringology/indexing/SuffixTrieNaive.cpp index de12582281..d25afe9b79 100644 --- a/alib2algo/src/stringology/indexing/SuffixTrieNaive.cpp +++ b/alib2algo/src/stringology/indexing/SuffixTrieNaive.cpp @@ -13,11 +13,11 @@ namespace stringology { namespace indexing { -indexes::SuffixTrie < DefaultSymbolType, unsigned > SuffixTrieNaive::construct ( const string::String & string ) { +indexes::SuffixTrie < DefaultSymbolType > SuffixTrieNaive::construct ( const string::String & string ) { return dispatch ( string.getData ( ) ); } -auto SuffixTrieNaiveLinearString = SuffixTrieNaive::RegistratorWrapper < indexes::SuffixTrie < DefaultSymbolType, unsigned >, string::LinearString < > > ( SuffixTrieNaive::construct ); +auto SuffixTrieNaiveLinearString = SuffixTrieNaive::RegistratorWrapper < indexes::SuffixTrie < DefaultSymbolType >, string::LinearString < > > ( SuffixTrieNaive::construct ); } /* namespace indexing */ diff --git a/alib2algo/src/stringology/indexing/SuffixTrieNaive.h b/alib2algo/src/stringology/indexing/SuffixTrieNaive.h index fe2e6ffaae..9d2b0a668f 100644 --- a/alib2algo/src/stringology/indexing/SuffixTrieNaive.h +++ b/alib2algo/src/stringology/indexing/SuffixTrieNaive.h @@ -23,24 +23,23 @@ namespace indexing { * Source: Lectures MI-EVY (CTU in Prague), Year 2014, Lecture 3, slide 4 */ -class SuffixTrieNaive : public std::SingleDispatch < SuffixTrieNaive, indexes::SuffixTrie < DefaultSymbolType, unsigned >, const string::StringBase & > { +class SuffixTrieNaive : public std::SingleDispatch < SuffixTrieNaive, indexes::SuffixTrie < DefaultSymbolType >, const string::StringBase & > { public: /** * Creates suffix trie * @param string string to construct suffix trie for * @return automaton */ - static indexes::SuffixTrie < DefaultSymbolType, unsigned > construct ( const string::String & string ); + static indexes::SuffixTrie < DefaultSymbolType > construct ( const string::String & string ); template < class SymbolType > - static indexes::SuffixTrie < SymbolType, unsigned > construct ( const string::LinearString < SymbolType > & string ); + static indexes::SuffixTrie < SymbolType > construct ( const string::LinearString < SymbolType > & string ); }; template < class SymbolType > -indexes::SuffixTrie < SymbolType, unsigned > SuffixTrieNaive::construct ( const string::LinearString < SymbolType > & w ) { +indexes::SuffixTrie < SymbolType > SuffixTrieNaive::construct ( const string::LinearString < SymbolType > & w ) { std::trie < SymbolType, std::variant < void, unsigned > > trie ( std::variant < void, unsigned > ( ( unsigned ) w.getContent ( ).size ( ) ) ); - std::set < unsigned > nodeAlphabet = { ( unsigned ) w.getContent ( ).size ( ) }; for ( unsigned i = w.getContent ( ).size ( ); i > 0; i-- ) { unsigned k = i - 1; @@ -54,11 +53,9 @@ indexes::SuffixTrie < SymbolType, unsigned > SuffixTrieNaive::construct ( const std::variant < void, unsigned > node = k + 1 < w.getContent ( ).size ( ) ? std::variant < void, unsigned >::from < void > ( ) : std::variant < void, unsigned > ( i - 1 ); n = & n->getChildren ( ).insert ( std::make_pair ( w.getContent ( )[k], std::trie < SymbolType, std::variant < void, unsigned > > ( node ) ) ).first->second; } - - nodeAlphabet.insert ( i - 1 ); } - return indexes::SuffixTrie < SymbolType, unsigned > ( w.getAlphabet ( ), nodeAlphabet, trie ); + return indexes::SuffixTrie < SymbolType > ( w.getAlphabet ( ), trie ); } } /* namespace indexing */ diff --git a/alib2algo/src/stringology/query/SuffixTrieFactors.cpp b/alib2algo/src/stringology/query/SuffixTrieFactors.cpp index 51e67dba6b..0667edcd19 100644 --- a/alib2algo/src/stringology/query/SuffixTrieFactors.cpp +++ b/alib2algo/src/stringology/query/SuffixTrieFactors.cpp @@ -13,7 +13,7 @@ namespace stringology { namespace query { -std::set < unsigned > SuffixTrieFactors::query ( const indexes::SuffixTrie < DefaultSymbolType, unsigned > & suffixTrie, const string::String & string ) { +std::set < unsigned > SuffixTrieFactors::query ( const indexes::SuffixTrie < DefaultSymbolType > & suffixTrie, const string::String & string ) { return dispatch ( suffixTrie, string.getData ( ) ); } diff --git a/alib2algo/src/stringology/query/SuffixTrieFactors.h b/alib2algo/src/stringology/query/SuffixTrieFactors.h index 45dc07edeb..0098f88c29 100644 --- a/alib2algo/src/stringology/query/SuffixTrieFactors.h +++ b/alib2algo/src/stringology/query/SuffixTrieFactors.h @@ -23,16 +23,17 @@ namespace query { * Source: ?? */ -class SuffixTrieFactors : public std::SingleDispatchFirstStaticParam < SuffixTrieFactors, std::set < unsigned >, const indexes::SuffixTrie < DefaultSymbolType, unsigned > &, const string::StringBase & > { - template < class SymbolType, class ValueType > - static void accumulateResult ( const std::trie < SymbolType, std::variant < void, ValueType > > & trie, std::set < ValueType > & res ) { - if ( trie.getData ( ).template is < ValueType > ( ) ) - res.insert ( trie.getData ( ).template get < ValueType > ( ) ); +class SuffixTrieFactors : public std::SingleDispatchFirstStaticParam < SuffixTrieFactors, std::set < unsigned >, const indexes::SuffixTrie < DefaultSymbolType > &, const string::StringBase & > { + template < class SymbolType > + static void accumulateResult ( const std::trie < SymbolType, std::variant < void, unsigned > > & trie, std::set < unsigned > & res ) { + if ( trie.getData ( ).template is < unsigned > ( ) ) + res.insert ( trie.getData ( ).template get < unsigned > ( ) ); - for ( const std::pair < SymbolType, std::trie < SymbolType, std::variant < void, ValueType > > > & child : trie.getChildren ( ) ) { + for ( const std::pair < SymbolType, std::trie < SymbolType, std::variant < void, unsigned > > > & child : trie.getChildren ( ) ) { accumulateResult ( child.second, res ); } } + public: /** * Query a suffix trie @@ -40,16 +41,16 @@ public: * @param string string to query by * @return occurences of factors */ - static std::set < unsigned > query ( const indexes::SuffixTrie < DefaultSymbolType, unsigned > & suffixTrie, const string::String & string ); + static std::set < unsigned > query ( const indexes::SuffixTrie < DefaultSymbolType > & suffixTrie, const string::String & string ); - template < class SymbolType, class ValueType > - static std::set < ValueType > query ( const indexes::SuffixTrie < SymbolType, ValueType > & suffixTrie, const string::LinearString < SymbolType > & string ); + template < class SymbolType > + static std::set < unsigned > query ( const indexes::SuffixTrie < SymbolType > & suffixTrie, const string::LinearString < SymbolType > & string ); }; -template < class SymbolType, class ValueType > -std::set < ValueType > SuffixTrieFactors::query ( const indexes::SuffixTrie < SymbolType, ValueType > & suffixTrie, const string::LinearString < SymbolType > & string ) { - const std::trie < SymbolType, std::variant < void, ValueType > > * node = & suffixTrie.getRoot ( ); +template < class SymbolType > +std::set < unsigned > SuffixTrieFactors::query ( const indexes::SuffixTrie < SymbolType > & suffixTrie, const string::LinearString < SymbolType > & string ) { + const std::trie < SymbolType, std::variant < void, unsigned > > * node = & suffixTrie.getRoot ( ); for ( const SymbolType & symbol : string.getContent ( ) ) { auto iter = node->getChildren ( ).find ( symbol ); if ( iter == node->getChildren ( ).end ( ) ) { @@ -58,7 +59,7 @@ std::set < ValueType > SuffixTrieFactors::query ( const indexes::SuffixTrie < Sy node = & iter->second; } - std::set < ValueType > res; + std::set < unsigned > res; accumulateResult ( * node, res ); return res; } diff --git a/alib2data/src/indexes/SuffixTrie.cpp b/alib2data/src/indexes/SuffixTrie.cpp index 6c84c9ea62..a832205c77 100644 --- a/alib2data/src/indexes/SuffixTrie.cpp +++ b/alib2data/src/indexes/SuffixTrie.cpp @@ -9,6 +9,6 @@ namespace alib { -auto suffixTreeParserRegister = xmlApi < alib::Object >::ParserRegister < indexes::SuffixTrie < > > ( ); +auto suffixTrieParserRegister = xmlApi < alib::Object >::ParserRegister < indexes::SuffixTrie < > > ( ); } /* namespace alib */ diff --git a/alib2data/src/indexes/SuffixTrie.h b/alib2data/src/indexes/SuffixTrie.h index 0cc29b818b..d8b4e8a3c9 100644 --- a/alib2data/src/indexes/SuffixTrie.h +++ b/alib2data/src/indexes/SuffixTrie.h @@ -16,8 +16,7 @@ #include <algorithm> #include <sstream> -#include <common/DefaultNodeType.h> -#include <common/DefaultEdgeType.h> +#include <common/DefaultSymbolType.h> #include <core/components.hpp> #include <exception/CommonException.h> @@ -34,70 +33,59 @@ #include <container/ObjectsVariant.h> #include <object/Void.h> +#include <primitive/Unsigned.h> + namespace indexes { -class EdgeAlphabet; -class NodeAlphabet; +class GeneralAlphabet; /** * Represents regular expression parsed from the XML. Regular expression is stored * as a tree of RegExpElement. */ -template < class EdgeType = DefaultEdgeType, class NodeType = DefaultNodeType > -class SuffixTrie : public alib::ObjectBase, public std::Components < SuffixTrie < EdgeType, NodeType >, EdgeType, std::tuple < EdgeAlphabet >, std::tuple < >, NodeType, std::tuple < NodeAlphabet >, std::tuple < > > { +template < class SymbolType = DefaultSymbolType > +class SuffixTrie : public alib::ObjectBase, public std::Components < SuffixTrie < SymbolType >, SymbolType, std::tuple < GeneralAlphabet >, std::tuple < > > { protected: - std::trie < EdgeType, std::variant < void, NodeType > > m_trie; + std::trie < SymbolType, std::variant < void, unsigned > > m_trie; public: /** - * @copydoc SuffixTrieNode::clone() const + * @copydoc SuffixTrie::clone() const */ virtual ObjectBase * clone ( ) const; /** - * @copydoc SuffixTrieNode::plunder() const + * @copydoc SuffixTrie::plunder() const */ virtual ObjectBase * plunder ( ) &&; - explicit SuffixTrie ( std::set < EdgeType > edgeAlphabet, std::set < NodeType > nodeAlphabet ); - explicit SuffixTrie ( std::set < EdgeType > edgeAlphabet, std::set < NodeType > nodeAlphabet, std::trie < EdgeType, std::variant < void, NodeType > > trie ); - explicit SuffixTrie ( std::trie < EdgeType, std::variant < void, NodeType > > trie ); + explicit SuffixTrie ( std::set < SymbolType > edgeAlphabet ); + explicit SuffixTrie ( std::set < SymbolType > edgeAlphabet, std::trie < SymbolType, std::variant < void, unsigned > > trie ); + explicit SuffixTrie ( std::trie < SymbolType, std::variant < void, unsigned > > trie ); - void checkTrie ( const std::trie < EdgeType, std::variant < void, NodeType > > & trie ); + void checkTrie ( const std::trie < SymbolType, std::variant < void, unsigned > > & trie ); /** * @return Root node of the trie */ - const std::trie < EdgeType, std::variant < void, NodeType > > & getRoot ( ) const; - - const std::set < EdgeType > & getEdgeAlphabet ( ) const { - return this->template accessComponent < EdgeAlphabet > ( ).get ( ); - } + const std::trie < SymbolType, std::variant < void, unsigned > > & getRoot ( ) const; - const std::set < NodeType > & getNodeAlphabet ( ) const { - return this->template accessComponent < NodeAlphabet > ( ).get ( ); + const std::set < SymbolType > & getAlphabet ( ) const { + return this->template accessComponent < GeneralAlphabet > ( ).get ( ); } /** * Sets the root node of the regular expression tree * @param tree root node to set */ - void setTree ( std::trie < EdgeType, std::variant < void, NodeType > > tree ); - - /** - * Removes symbol from the alphabet of symbol available in the regular expression - * @param symbol removed symbol from the alphabet - */ - bool removeSymbolFromEdgeAlphabet ( const EdgeType & symbol ) { - return this->template accessComponent < EdgeAlphabet > ( ).remove ( symbol ); - } + void setTree ( std::trie < SymbolType, std::variant < void, unsigned > > tree ); /** * Removes symbol from the alphabet of symbol available in the regular expression * @param symbol removed symbol from the alphabet */ - bool removeSymbolFromNodeAlphabet ( const NodeType & symbol ) { - return this->template accessComponent < NodeAlphabet > ( ).remove ( symbol ); + bool removeSymbolFromEdgeAlphabet ( const SymbolType & symbol ) { + return this->template accessComponent < GeneralAlphabet > ( ).remove ( symbol ); } /** @@ -134,97 +122,92 @@ public: namespace indexes { -template < class EdgeType, class NodeType > -SuffixTrie < EdgeType, NodeType >::SuffixTrie ( std::set < EdgeType > edgeAlphabet, std::set < NodeType > nodeAlphabet ) : SuffixTrie ( std::move ( edgeAlphabet ), std::move ( nodeAlphabet ), std::trie < EdgeType, std::variant < void, NodeType > > ( std::variant < void, NodeType >::template from < void > ( ) ) ) { +template < class SymbolType > +SuffixTrie < SymbolType >::SuffixTrie ( std::set < SymbolType > edgeAlphabet ) : SuffixTrie ( std::move ( edgeAlphabet ), std::trie < SymbolType, std::variant < void, unsigned > > ( std::variant < void, unsigned >::template from < void > ( ) ) ) { } -template < class EdgeType, class NodeType > -SuffixTrie < EdgeType, NodeType >::SuffixTrie ( std::set < EdgeType > edgeAlphabet, std::set < NodeType > nodeAlphabet, std::trie < EdgeType, std::variant < void, NodeType > > trie ) : std::Components < SuffixTrie, EdgeType, std::tuple < EdgeAlphabet >, std::tuple < >, NodeType, std::tuple < NodeAlphabet >, std::tuple < > > ( std::make_tuple ( std::move ( edgeAlphabet ) ), std::tuple < > ( ), std::make_tuple ( std::move ( nodeAlphabet ) ), std::tuple < > ( ) ), m_trie ( std::move ( trie ) ) { +template < class SymbolType > +SuffixTrie < SymbolType >::SuffixTrie ( std::set < SymbolType > edgeAlphabet, std::trie < SymbolType, std::variant < void, unsigned > > trie ) : std::Components < SuffixTrie, SymbolType, std::tuple < GeneralAlphabet >, std::tuple < > > ( std::make_tuple ( std::move ( edgeAlphabet ) ), std::tuple < > ( ) ), m_trie ( std::move ( trie ) ) { checkTrie ( this->m_trie ); } -template < class EdgeType, class NodeType > -SuffixTrie < EdgeType, NodeType >::SuffixTrie ( std::trie < EdgeType, std::variant < void, NodeType > > trie ) : SuffixTrie ( computeMinimalEdgeAlphabet ( trie ), computeMinimalNodeAlphabet ( trie ), trie ) { +template < class SymbolType > +SuffixTrie < SymbolType >::SuffixTrie ( std::trie < SymbolType, std::variant < void, unsigned > > trie ) : SuffixTrie ( computeMinimalEdgeAlphabet ( trie ), trie ) { } -template < class EdgeType, class NodeType > -alib::ObjectBase * SuffixTrie < EdgeType, NodeType >::clone ( ) const { +template < class SymbolType > +alib::ObjectBase * SuffixTrie < SymbolType >::clone ( ) const { return new SuffixTrie ( * this ); } -template < class EdgeType, class NodeType > -alib::ObjectBase * SuffixTrie < EdgeType, NodeType >::plunder ( ) && { +template < class SymbolType > +alib::ObjectBase * SuffixTrie < SymbolType >::plunder ( ) && { return new SuffixTrie ( std::move ( * this ) ); } -template < class EdgeType, class NodeType > -void SuffixTrie < EdgeType, NodeType >::checkTrie ( const std::trie < EdgeType, std::variant < void, NodeType > > & trie ) { - if ( trie.getData ( ).template is < NodeType > ( ) && ! getNodeAlphabet ( ).count ( trie.getData ( ).template get < NodeType > ( ) ) ) - throw exception::CommonException ( "Node symbols not in the node alphabet." ); - - for ( const std::pair < const EdgeType, std::trie < EdgeType, std::variant < void, NodeType > > > & child : trie.getChildren ( ) ) { - if ( ! getEdgeAlphabet ( ).count ( child.first ) ) - throw exception::CommonException ( "Node symbols not in the node alphabet." ); +template < class SymbolType > +void SuffixTrie < SymbolType >::checkTrie ( const std::trie < SymbolType, std::variant < void, unsigned > > & trie ) { + for ( const std::pair < const SymbolType, std::trie < SymbolType, std::variant < void, unsigned > > > & child : trie.getChildren ( ) ) { + if ( ! getAlphabet ( ).count ( child.first ) ) + throw exception::CommonException ( "Symbol " + std::to_string ( child.first ) + "not in the alphabet." ); checkTrie ( child.second ); } } -template < class EdgeType, class NodeType > -const std::trie < EdgeType, std::variant < void, NodeType > > & SuffixTrie < EdgeType, NodeType >::getRoot ( ) const { +template < class SymbolType > +const std::trie < SymbolType, std::variant < void, unsigned > > & SuffixTrie < SymbolType >::getRoot ( ) const { return m_trie; } -template < class EdgeType, class NodeType > -void SuffixTrie < EdgeType, NodeType >::setTree ( std::trie < EdgeType, std::variant < void, NodeType > > trie ) { +template < class SymbolType > +void SuffixTrie < SymbolType >::setTree ( std::trie < SymbolType, std::variant < void, unsigned > > trie ) { checkTrie ( trie ); this->m_trie = std::move ( trie ).plunder ( ); } -template < class EdgeType, class NodeType > -void SuffixTrie < EdgeType, NodeType >::operator >>( std::ostream & out ) const { +template < class SymbolType > +void SuffixTrie < SymbolType >::operator >>( std::ostream & out ) const { out << "(SuffixTrie " << this->m_trie << ")"; } -template < class EdgeType, class NodeType > -int SuffixTrie < EdgeType, NodeType >::compare ( const SuffixTrie & other ) const { - auto first = std::tie ( getRoot ( ), getEdgeAlphabet ( ), getNodeAlphabet ( ) ); - auto second = std::tie ( other.getRoot ( ), other.getEdgeAlphabet ( ), getNodeAlphabet ( ) ); +template < class SymbolType > +int SuffixTrie < SymbolType >::compare ( const SuffixTrie & other ) const { + auto first = std::tie ( getRoot ( ), getAlphabet ( ) ); + auto second = std::tie ( other.getRoot ( ), other.getAlphabet ( ) ); static std::compare < decltype ( first ) > comp; return comp ( first, second ); } -template < class EdgeType, class NodeType > -SuffixTrie < EdgeType, NodeType >::operator std::string ( ) const { +template < class SymbolType > +SuffixTrie < SymbolType >::operator std::string ( ) const { std::stringstream ss; ss << * this; return ss.str ( ); } -template < class EdgeType, class NodeType > -SuffixTrie < EdgeType, NodeType > SuffixTrie < EdgeType, NodeType >::parse ( std::deque < sax::Token >::iterator & input ) { +template < class SymbolType > +SuffixTrie < SymbolType > SuffixTrie < SymbolType >::parse ( std::deque < sax::Token >::iterator & input ) { sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, SuffixTrie::getXmlTagName() ); - std::set < EdgeType > edgeAlphabet = alib::xmlApi < std::set < EdgeType > >::parse ( input ); - std::set < NodeType > nodeAlphabet = alib::xmlApi < std::set < NodeType > >::parse ( input ); - std::trie < EdgeType, std::variant < void, NodeType > > root = alib::xmlApi < std::trie < EdgeType, std::variant < void, NodeType > > >::parse ( input ); - SuffixTrie < EdgeType, NodeType > trie ( std::move ( edgeAlphabet ), std::move ( nodeAlphabet ), std::move ( root ) ); + std::set < SymbolType > edgeAlphabet = alib::xmlApi < std::set < SymbolType > >::parse ( input ); + std::trie < SymbolType, std::variant < void, unsigned > > root = alib::xmlApi < std::trie < SymbolType, std::variant < void, unsigned > > >::parse ( input ); + SuffixTrie < SymbolType > trie ( std::move ( edgeAlphabet ), std::move ( root ) ); sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, SuffixTrie::getXmlTagName() ); return trie; } -template < class EdgeType, class NodeType > -void SuffixTrie < EdgeType, NodeType >::compose ( std::deque < sax::Token > & out ) const { +template < class SymbolType > +void SuffixTrie < SymbolType >::compose ( std::deque < sax::Token > & out ) const { out.emplace_back ( SuffixTrie::getXmlTagName(), sax::Token::TokenType::START_ELEMENT ); - alib::xmlApi < std::set < EdgeType > >::compose ( out, getEdgeAlphabet ( ) ); - alib::xmlApi < std::set < NodeType > >::compose ( out, getNodeAlphabet ( ) ); - alib::xmlApi < std::trie < EdgeType, std::variant < void, NodeType > > >::compose ( out, getRoot ( ) ); + alib::xmlApi < std::set < SymbolType > >::compose ( out, getAlphabet ( ) ); + alib::xmlApi < std::trie < SymbolType, std::variant < void, unsigned > > >::compose ( out, getRoot ( ) ); out.emplace_back ( SuffixTrie::getXmlTagName(), sax::Token::TokenType::END_ELEMENT ); } -template < class EdgeType, class NodeType > -alib::ObjectBase* SuffixTrie < EdgeType, NodeType >::inc() && { +template < class SymbolType > +alib::ObjectBase* SuffixTrie < SymbolType >::inc() && { return new alib::UniqueObject(alib::Object(std::move(*this)), primitive::Integer(0)); } @@ -232,11 +215,11 @@ alib::ObjectBase* SuffixTrie < EdgeType, NodeType >::inc() && { namespace std { -template < class EdgeType, class NodeType > -class ComponentConstraint < indexes::SuffixTrie < EdgeType, NodeType >, EdgeType, indexes::EdgeAlphabet > { +template < class SymbolType > +class ComponentConstraint < indexes::SuffixTrie < SymbolType >, SymbolType, indexes::GeneralAlphabet > { - static bool used ( const std::trie < EdgeType, std::variant < void, NodeType > > & trie, const EdgeType & symbol ) { - for ( const std::pair < const EdgeType, std::trie < EdgeType, std::variant < void, NodeType > > > & child : trie.getChildren ( ) ) { + static bool used ( const std::trie < SymbolType, std::variant < void, unsigned > > & trie, const SymbolType & symbol ) { + for ( const std::pair < const SymbolType, std::trie < SymbolType, std::variant < void, unsigned > > > & child : trie.getChildren ( ) ) { if ( symbol == child.first || checkTrie ( trie, child.second ) ) return true; } @@ -244,42 +227,15 @@ class ComponentConstraint < indexes::SuffixTrie < EdgeType, NodeType >, EdgeType } public: - static bool used ( const indexes::SuffixTrie < EdgeType, NodeType > & index, const EdgeType & symbol ) { - return used ( index.getRoot ( ), symbol ); - } - - static bool available ( const indexes::SuffixTrie < EdgeType, NodeType > &, const EdgeType & ) { - return true; - } - - static void valid ( const indexes::SuffixTrie < EdgeType, NodeType > &, const EdgeType & ) { - } -}; - -template < class EdgeType, class NodeType > -class ComponentConstraint < indexes::SuffixTrie < EdgeType, NodeType >, NodeType, indexes::NodeAlphabet > { - - static bool used ( const std::trie < EdgeType, std::variant < void, NodeType > > & trie, const NodeType & symbol ) { - if ( trie.getData ( ).template is < NodeType > ( ) && symbol == trie.getData ( ).template get < NodeType > ( ) ) - return true; - - for ( const std::pair < const EdgeType, std::trie < EdgeType, std::variant < void, NodeType > > > & child : trie.getChildren ( ) ) { - if ( used ( trie, child.second ) ) - return true; - } - return false; - } - -public: - static bool used ( const indexes::SuffixTrie < EdgeType, NodeType > & index, const NodeType & symbol ) { + static bool used ( const indexes::SuffixTrie < SymbolType > & index, const SymbolType & symbol ) { return used ( index.getRoot ( ), symbol ); } - static bool available ( const indexes::SuffixTrie < EdgeType, NodeType > &, const NodeType & ) { + static bool available ( const indexes::SuffixTrie < SymbolType > &, const SymbolType & ) { return true; } - static void valid ( const indexes::SuffixTrie < EdgeType, NodeType > &, const NodeType & ) { + static void valid ( const indexes::SuffixTrie < SymbolType > &, const SymbolType & ) { } }; diff --git a/aquery2/src/aquery.cpp b/aquery2/src/aquery.cpp index 00aebf4392..93322a3f62 100644 --- a/aquery2/src/aquery.cpp +++ b/aquery2/src/aquery.cpp @@ -56,7 +56,7 @@ int main ( int argc, char * argv[] ) { measurements::start ( "Input read", measurements::Type::AUXILIARY ); if ( query.getValue ( ) == "suffixTrieFactors" ) { - indexes::SuffixTrie < DefaultSymbolType, unsigned > suffixTrie = alib::XmlDataFactory::fromTokens < indexes::SuffixTrie < DefaultSymbolType, unsigned > > ( sax::FromXMLParserHelper::parseInput ( indexInput ) ); + indexes::SuffixTrie < DefaultSymbolType > suffixTrie = alib::XmlDataFactory::fromTokens < indexes::SuffixTrie < DefaultSymbolType > > ( sax::FromXMLParserHelper::parseInput ( indexInput ) ); string::String pattern = alib::XmlDataFactory::fromTokens < string::String > ( std::move ( sax::FromXMLParserHelper::parseInput(true, patternInput).front ( ) ) ); measurements::end ( ); diff --git a/astringology2/src/astringology.cpp b/astringology2/src/astringology.cpp index bdd004454a..923f019a55 100644 --- a/astringology2/src/astringology.cpp +++ b/astringology2/src/astringology.cpp @@ -285,7 +285,7 @@ int main ( int argc, char * argv[] ) { measurements::end ( ); measurements::start ( "Algorithm", measurements::Type::MAIN ); - indexes::SuffixTrie < DefaultSymbolType, unsigned > suffixTrie = stringology::indexing::SuffixTrieNaive::construct ( subject ); + indexes::SuffixTrie < DefaultSymbolType > suffixTrie = stringology::indexing::SuffixTrieNaive::construct ( subject ); measurements::end ( ); measurements::start ( "Output write", measurements::Type::AUXILIARY ); -- GitLab