ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
LongestCommonSubsequence.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*-------------------- File LongestCommonSubsequence.h ---------------------*/
3/*--------------------------------------------------------------------------*/
43/*--------------------------------------------------------------------------*/
44/*----------------------------- DEFINITIONS --------------------------------*/
45/*--------------------------------------------------------------------------*/
46
47#ifndef __ADS_LongestCommonSubsequence
48 #define __ADS_LongestCommonSubsequence
49/* self-identification: #endif constant */
50
51/*--------------------------------------------------------------------------*/
52/*------------------------------ INCLUDES ----------------------------------*/
53/*--------------------------------------------------------------------------*/
54
55#include "ADS/Contract.h"
56
57#include <algorithm>
58#include <cstddef>
59#include <string>
60#include <tuple>
61#include <utility>
62#include <vector>
63
64/*--------------------------------------------------------------------------*/
65/*--------------------------- NAMESPACE ------------------------------------*/
66/*--------------------------------------------------------------------------*/
67
68namespace ADS
69{
70
92template< class S >
93std::vector< std::vector< int > > lcsTable( const S & P , const S & T );
94
115template< class S >
116int lcsMemo( const S & P , const S & T , long * solved = nullptr );
117
139template< class S >
140S lcs( const S & P , const S & T );
141
169template< class S >
170std::vector< std::pair< char , typename S::value_type > > diff( const S & P ,
171 const S & T );
172
196template< class S >
197std::tuple< std::size_t , std::size_t , std::size_t >
198longestCommonSubstring( const S & P , const S & T );
199
200/*--------------------------------------------------------------------------*/
201
202} // end( namespace ADS )
203
204/*--------------------------------------------------------------------------*/
205/*-------------------------- IMPLEMENTATION --------------------------------*/
206/*--------------------------------------------------------------------------*/
207
208#include "ADS/string/impl/LongestCommonSubsequence.tpp"
209
210/*--------------------------------------------------------------------------*/
211
212#endif /* LongestCommonSubsequence.h included */
213
214/*--------------------------------------------------------------------------*/
215/*------------------ End File LongestCommonSubsequence.h -------------------*/
216/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
std::vector< std::pair< char, typename S::value_type > > diff(const S &P, const S &T)
the differences from to : ( '-' , p ) for an item of only, ( '+' , t ) for an item of only,...
std::tuple< std::size_t, std::size_t, std::size_t > longestCommonSubstring(const S &P, const S &T)
the longest common substring: its length and where it ends in and , the first one found by rows of ;...
std::vector< std::vector< int > > lcsTable(const S &P, const S &T)
the table of the lengths of the LCS of the prefixes of and
int lcsMemo(const S &P, const S &T, long *solved=nullptr)
the length of the LCS by the memoization of the book, marking the subproblems not solved yet; the nu...
S lcs(const S &P, const S &T)
a longest common subsequence, read back from the table
Definition ADT.h:96