diff --git a/alib2data/src/indexes/stringology/SuffixArray.h b/alib2data/src/indexes/stringology/SuffixArray.h index 1b02f70471acda4b5b176eeec25815a4c872ee62..567923f0617d0405f6de6dedb62c847d668daea1 100644 --- a/alib2data/src/indexes/stringology/SuffixArray.h +++ b/alib2data/src/indexes/stringology/SuffixArray.h @@ -45,7 +45,6 @@ #include <primitive/xml/Unsigned.h> #include <container/ObjectsVector.h> - #include <container/xml/ObjectsVector.h> #include <string/LinearString.h> @@ -64,74 +63,133 @@ namespace stringology { */ template < class SymbolType = DefaultSymbolType > class SuffixArray final : public object::ObjectBase { + /** + * Representation of lexicographically sorted indexes to the indexed string.. + */ ext::vector < unsigned > m_data; + + /** + * The copy of indexed string. + */ string::LinearString < SymbolType > m_string; public: /** - * @copydoc SuffixTrieNode::clone ( ) const & + * @copydoc ObjectBase::clone ( ) const & */ - virtual ObjectBase * clone ( ) const &; + virtual ObjectBase * clone ( ) const & override; /** - * @copydoc SuffixTrieNode::clone ( ) const & + * @copydoc ObjectBase::clone ( ) && */ - virtual ObjectBase * clone ( ) &&; + virtual ObjectBase * clone ( ) && override; + /** + * Creates a new instance of the index with concrete sorted indexes and indexed string. + * + * \param data the sorted indexes to the indexed string + * \param string the indexed string + */ explicit SuffixArray ( ext::vector < unsigned > data, string::LinearString < SymbolType > string ); /** - * @return Root node of the trie + * Getter of the sorted indexes. + * + * @return vector of indexes */ const ext::vector < unsigned > & getData ( ) const &; + /** + * Getter of the sorted indexes. + * + * @return vector of indexes + */ ext::vector < unsigned > && getData ( ) &&; + /** + * Getter of the indexed string. + * + * @return the indexed string + */ const string::LinearString < SymbolType > & getString ( ) const &; + /** + * Getter of the indexed string. + * + * @return the indexed string + */ string::LinearString < SymbolType > && getString ( ) &&; + /** + * Getter of the alphabet of the indexed string. + * + * \returns the alphabet of the indexed string + */ const ext::set < SymbolType > & getAlphabet ( ) const & { return m_string.getAlphabet ( ); } + /** + * Getter of the alphabet of the indexed string. + * + * \returns the alphabet of the indexed string + */ ext::set < SymbolType > && getAlphabet ( ) && { return std::move ( m_string ).getAlphabet ( ); } /** - * Sets the root node of the regular expression tree - * @param tree root node to set + * Sets the vector of sorted indexes to the indexed string. + * + * @param data new vector of indexes */ void setData ( ext::vector < unsigned > data ); /** - * Removes symbol from the alphabet of symbol available in the regular expression - * @param symbol removed symbol from the alphabet + * Remover of a symbol from the alphabet of indexed string. + * + * \param symbol a symbol to remove. */ bool removeSymbolFromAlphabet ( const SymbolType & symbol ) { return m_string.removeSymbol ( symbol ); } /** - * Prints XML representation of the tree to the output stream. - * @param out output stream to which print the tree - * @param tree tree to print + * @copydoc alib::CommonBase<ObjectBase>::compare ( const ObjectBase & ) */ - virtual void operator >>( std::ostream & out ) const; - - virtual int compare ( const ObjectBase & other ) const { + virtual int compare ( const ObjectBase & other ) const override { if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return this->compare ( ( decltype ( * this ) )other ); return ext::type_index ( typeid ( * this ) ) - ext::type_index ( typeid ( other ) ); } - virtual int compare ( const SuffixArray & other ) const; + /** + * The actual compare method. + * + * \param other the other instance + * + * \returns the actual relation between two by type same index instances + */ + int compare ( const SuffixArray & other ) const; + + /** + * @copydoc alib::CommonBase<ObjectBase>::operator >> ( std::ostream & ) + */ + virtual void operator >>( std::ostream & out ) const override; - virtual explicit operator std::string ( ) const; + /** + * @copydoc alib::CommonBase<ObjectBase>::operator std::string ( ) + */ + virtual explicit operator std::string ( ) const override; - virtual object::ObjectBase * inc ( ) &&; + /** + * @copydoc alib::ObjectBase::inc() + */ + virtual object::ObjectBase * inc ( ) && override; + /** + * Type of normalized index. + */ typedef SuffixArray < > normalized_type; }; @@ -145,7 +203,6 @@ namespace stringology { template < class SymbolType > SuffixArray < SymbolType >::SuffixArray ( ext::vector < unsigned > data, string::LinearString < SymbolType > string ) : m_data ( std::move ( data ) ), m_string ( std::move ( string ) ) { - // TODO check validity of the string like in LinearString } template < class SymbolType > @@ -216,6 +273,11 @@ object::ObjectBase* SuffixArray < SymbolType >::inc() && { namespace core { +/** + * Helper for normalisation of types specified by templates used as internal datatypes of symbols. + * + * \returns new instance of the index with default template parameters or unmodified instance if the template parameters were already the default ones + */ template < class SymbolType > struct normalize < indexes::stringology::SuffixArray < SymbolType >, typename std::enable_if < ! std::is_same < indexes::stringology::SuffixArray < SymbolType >, indexes::stringology::SuffixArray < > >::value >::type > { static indexes::stringology::SuffixArray < > eval ( indexes::stringology::SuffixArray < SymbolType > && value ) { diff --git a/alib2data/src/indexes/stringology/SuffixAutomaton.h b/alib2data/src/indexes/stringology/SuffixAutomaton.h index 3b326a8f45bacb32f716e354c3ef3c02eab4845e..7f28b6d8b76318a14e5777034ff9fb95736a75e6 100644 --- a/alib2data/src/indexes/stringology/SuffixAutomaton.h +++ b/alib2data/src/indexes/stringology/SuffixAutomaton.h @@ -146,11 +146,11 @@ public: } /** - * The actual compare method + * The actual compare method. * * \param other the other instance * - * \returns the actual relation between two by type same automata instances + * \returns the actual relation between two by type same index instances */ int compare ( const SuffixAutomaton & other ) const; @@ -255,7 +255,7 @@ namespace core { /** * Helper for normalisation of types specified by templates used as internal datatypes of symbols. * - * \returns new instance of the automaton with default template parameters or unmodified instance if the template parameters were already the default ones + * \returns new instance of the index with default template parameters or unmodified instance if the template parameters were already the default ones */ template < class SymbolType > struct normalize < indexes::stringology::SuffixAutomaton < SymbolType >, typename std::enable_if < ! std::is_same < indexes::stringology::SuffixAutomaton < SymbolType >, indexes::stringology::SuffixAutomaton < > >::value >::type > { diff --git a/alib2data/src/indexes/stringology/SuffixTrie.h b/alib2data/src/indexes/stringology/SuffixTrie.h index 97115116c7895f4d1c772701b9021292a2d31f2c..f635c3f5ff4f818ab99d733ce0331298310a4469 100644 --- a/alib2data/src/indexes/stringology/SuffixTrie.h +++ b/alib2data/src/indexes/stringology/SuffixTrie.h @@ -120,14 +120,14 @@ public: /** * Getter of the raw suffix trie. * - * \return Root node of the trie + * \return root node of the trie */ const ext::trie < SymbolType, ext::variant < void, unsigned > > & getRoot ( ) const &; /** * Getter of the raw suffix trie. * - * \return Root node of the trie + * \return root node of the trie */ ext::trie < SymbolType, ext::variant < void, unsigned > > && getRoot ( ) &&; @@ -179,7 +179,7 @@ public: * * \param other the other instance * - * \returns the actual relation between two by type same automata instances + * \returns the actual relation between two by type same index instances */ int compare ( const SuffixTrie & other ) const; @@ -355,7 +355,7 @@ public: /** * Helper for normalisation of types specified by templates used as internal datatypes of symbols. * - * \returns new instance of the automaton with default template parameters or unmodified instance if the template parameters were already the default ones + * \returns new instance of the index with default template parameters or unmodified instance if the template parameters were already the default ones */ template < class SymbolType > struct normalize < indexes::stringology::SuffixTrie < SymbolType >, typename std::enable_if < ! std::is_same < indexes::stringology::SuffixTrie < SymbolType >, indexes::stringology::SuffixTrie < > >::value >::type > {