Program Listing for File Palindromes.h
↰ Return to documentation for file (ADS/string/Palindromes.h)
/*--------------------------------------------------------------------------*/
/*--------------------------- File Palindromes.h ---------------------------*/
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/*----------------------------- DEFINITIONS --------------------------------*/
/*--------------------------------------------------------------------------*/
#ifndef __ADS_Palindromes
#define __ADS_Palindromes
/* self-identification: #endif constant */
/*--------------------------------------------------------------------------*/
/*------------------------------ INCLUDES ----------------------------------*/
/*--------------------------------------------------------------------------*/
#include "ADS/Contract.h"
#include "ADS/string/LongestCommonSubsequence.h"
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <string>
#include <string_view>
#include <type_traits>
#include <utility>
#include <vector>
/*--------------------------------------------------------------------------*/
/*--------------------------- NAMESPACE ------------------------------------*/
/*--------------------------------------------------------------------------*/
namespace ADS {
template< class S > requires std::is_class_v< S >
[[nodiscard]] std::pair< std::size_t , std::size_t > longestPalindrome(
const S & s );
template< class S > requires std::is_class_v< S >
[[nodiscard]] S longestPalindromicSubstring( const S & s );
[[nodiscard]] inline std::string longestPalindromicSubstring(
const std::string & s );
template< class S > requires std::is_class_v< S >
[[nodiscard]] S longestPalindromicSubsequence( const S & s );
[[nodiscard]] inline std::string longestPalindromicSubsequence(
const std::string & s );
template< class S > requires std::is_class_v< S >
[[nodiscard]] std::vector< S > palindromicPartition( const S & s );
[[nodiscard]] inline std::vector< std::string > palindromicPartition(
const std::string & s );
/*--------------------------------------------------------------------------*/
/*----------------------------- CLASS Eertree ------------------------------*/
/*--------------------------------------------------------------------------*/
class Eertree {
/*--------------------------------------------------------------------------*/
public:
Eertree( void );
explicit Eertree( std::string_view s );
bool add( unsigned char c );
[[nodiscard]] std::size_t distinct( void ) const {
return( f_len.size() - 2 );
}
[[nodiscard]] std::size_t suffixLength( void ) const {
return( std::size_t( f_len[ f_last ] ) );
}
[[nodiscard]] std::size_t size( void ) const { return( f_s.size() ); }
/*--------------------------------------------------------------------------*/
private:
friend std::vector< std::string > palindromicFactorization(
std::string_view s );
[[nodiscard]] std::uint32_t extensible( std::uint32_t v ,
unsigned char c ) const;
std::string f_s;
std::vector< long > f_len;
std::vector< std::uint32_t > f_link;
std::vector< long > f_diff;
std::vector< std::uint32_t > f_series;
std::vector< std::vector< std::pair< unsigned char , std::uint32_t > > >
f_next;
std::uint32_t f_last = 1;
}; // end( class Eertree )
[[nodiscard]] inline std::vector< std::string > palindromicFactorization(
std::string_view s );
/*--------------------------------------------------------------------------*/
} // end( namespace ADS )
/*--------------------------------------------------------------------------*/
/*-------------------------- IMPLEMENTATION --------------------------------*/
/*--------------------------------------------------------------------------*/
#include "ADS/string/impl/Palindromes.tpp"
/*--------------------------------------------------------------------------*/
#endif /* Palindromes.h included */
/*--------------------------------------------------------------------------*/
/*------------------------- End File Palindromes.h -------------------------*/
/*--------------------------------------------------------------------------*/