ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
Palindromes.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*--------------------------- File Palindromes.h ---------------------------*/
3/*--------------------------------------------------------------------------*/
96/*--------------------------------------------------------------------------*/
97/*----------------------------- DEFINITIONS --------------------------------*/
98/*--------------------------------------------------------------------------*/
99
100#ifndef __ADS_Palindromes
101 #define __ADS_Palindromes
102/* self-identification: #endif constant */
103
104/*--------------------------------------------------------------------------*/
105/*------------------------------ INCLUDES ----------------------------------*/
106/*--------------------------------------------------------------------------*/
107
108#include "ADS/Contract.h"
110
111#include <algorithm>
112#include <cstddef>
113#include <cstdint>
114#include <string>
115#include <string_view>
116#include <type_traits>
117#include <utility>
118#include <vector>
119
120/*--------------------------------------------------------------------------*/
121/*--------------------------- NAMESPACE ------------------------------------*/
122/*--------------------------------------------------------------------------*/
123
124namespace ADS
125{
126
165template< class S >
166 requires std::is_class_v< S >
167[[nodiscard]] std::pair< std::size_t , std::size_t >
168longestPalindrome( const S & s );
169
181template< class S >
182 requires std::is_class_v< S >
183[[nodiscard]] S longestPalindromicSubstring( const S & s );
184
187[[nodiscard]] inline std::string
188longestPalindromicSubstring( const std::string & s );
189
222template< class S >
223 requires std::is_class_v< S >
224[[nodiscard]] S longestPalindromicSubsequence( const S & s );
225
228[[nodiscard]] inline std::string
229longestPalindromicSubsequence( const std::string & s );
230
262template< class S >
263 requires std::is_class_v< S >
264[[nodiscard]] std::vector< S > palindromicPartition( const S & s );
265
268[[nodiscard]] inline std::vector< std::string >
269palindromicPartition( const std::string & s );
270
271/*--------------------------------------------------------------------------*/
272/*----------------------------- CLASS Eertree ------------------------------*/
273/*--------------------------------------------------------------------------*/
274
277{
278
279/*--------------------------------------------------------------------------*/
280 public:
283 Eertree( void );
284
286 explicit Eertree( std::string_view s );
287
317 bool add( unsigned char c );
318
320 [[nodiscard]] std::size_t distinct( void ) const {
321 return( f_len.size() - 2 );
322 }
323
325 [[nodiscard]] std::size_t suffixLength( void ) const {
326 return( std::size_t( f_len[ f_last ] ) );
327 }
328
330 [[nodiscard]] std::size_t size( void ) const { return( f_s.size() ); }
331
332/*--------------------------------------------------------------------------*/
333 private:
334 friend std::vector< std::string >
335 palindromicFactorization( std::string_view s );
336
339 [[nodiscard]] std::uint32_t extensible( std::uint32_t v ,
340 unsigned char c ) const;
341
342 std::string f_s;
343 std::vector< long > f_len;
344 std::vector< std::uint32_t > f_link;
345 std::vector< long > f_diff;
346 std::vector< std::uint32_t > f_series;
347 std::vector< std::vector< std::pair< unsigned char , std::uint32_t > > >
348 f_next;
349 std::uint32_t f_last = 1;
350
351 }; // end( class Eertree )
352
379[[nodiscard]] inline std::vector< std::string >
380palindromicFactorization( std::string_view s );
381
382/*--------------------------------------------------------------------------*/
383
384} // end( namespace ADS )
385
386/*--------------------------------------------------------------------------*/
387/*-------------------------- IMPLEMENTATION --------------------------------*/
388/*--------------------------------------------------------------------------*/
389
390#include "ADS/string/impl/Palindromes.tpp"
391
392/*--------------------------------------------------------------------------*/
393
394#endif /* Palindromes.h included */
395
396/*--------------------------------------------------------------------------*/
397/*------------------------- End File Palindromes.h -------------------------*/
398/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The longest common subsequence (LCS) of and , the reality check of section 13.7 of the book: ,...
Eertree(std::string_view s)
the eertree of , by add() on each of its bytes
std::size_t distinct(void) const
the number of the distinct nonempty palindromes of the string
Definition Palindromes.h:320
Eertree(void)
the eertree of the empty string: the two roots, of length and 0
std::size_t suffixLength(void) const
the length of the longest palindromic suffix of the string
Definition Palindromes.h:325
std::size_t size(void) const
the length of the string
Definition Palindromes.h:330
bool add(unsigned char c)
adds the byte at the end; whether the longest palindromic suffix of the new string occurs there for ...
friend std::vector< std::string > palindromicFactorization(std::string_view s)
the fewest palindromes into which can be cut, in their order, by the series of the eertree,...
S longestPalindromicSubstring(const S &s)
the leftmost of the longest palindromic substrings of
std::vector< S > palindromicPartition(const S &s)
the fewest palindromes into which can be cut, in their order; none for the empty
std::vector< std::string > palindromicFactorization(std::string_view s)
the fewest palindromes into which can be cut, in their order, by the series of the eertree,...
std::pair< std::size_t, std::size_t > longestPalindrome(const S &s)
where a longest palindromic substring of starts and its length, the leftmost one among the longest; ...
S longestPalindromicSubsequence(const S &s)
a longest palindromic subsequence of
Definition ADT.h:96