ADS
Algorithms and Data Structures
Toggle main menu visibility
Loading...
Searching...
No Matches
SuffixAutomaton.h
Go to the documentation of this file.
1
/*--------------------------------------------------------------------------*/
2
/*------------------------- File SuffixAutomaton.h -------------------------*/
3
/*--------------------------------------------------------------------------*/
61
/*--------------------------------------------------------------------------*/
62
/*----------------------------- DEFINITIONS --------------------------------*/
63
/*--------------------------------------------------------------------------*/
64
65
#ifndef __ADS_SuffixAutomaton
66
#define __ADS_SuffixAutomaton
67
/* self-identification: #endif constant */
68
69
/*--------------------------------------------------------------------------*/
70
/*------------------------------ INCLUDES ----------------------------------*/
71
/*--------------------------------------------------------------------------*/
72
73
#include "
ADS/Contract.h
"
74
75
#include <cstddef>
76
#include <cstdint>
77
#include <string_view>
78
#include <utility>
79
#include <vector>
80
81
/*--------------------------------------------------------------------------*/
82
/*--------------------------- NAMESPACE ------------------------------------*/
83
/*--------------------------------------------------------------------------*/
84
85
namespace
ADS
86
{
87
88
/*--------------------------------------------------------------------------*/
89
/*------------------------ CLASS SuffixAutomaton ---------------------------*/
90
/*--------------------------------------------------------------------------*/
91
93
class
SuffixAutomaton
94
{
95
96
/*--------------------------------------------------------------------------*/
97
public
:
99
SuffixAutomaton
(
void
);
100
102
explicit
SuffixAutomaton
( std::string_view S );
103
135
void
extend
(
unsigned
char
c );
136
139
[[nodiscard]]
bool
contains
( std::string_view P )
const
;
140
161
[[nodiscard]] std::size_t
occurrences
( std::string_view P )
const
;
162
166
[[nodiscard]] std::size_t
distinctSubstrings
(
void
)
const
;
167
191
[[nodiscard]] std::pair< std::size_t , std::size_t >
192
longestCommonSubstring
( std::string_view T )
const
;
193
195
[[nodiscard]] std::size_t
states
(
void
)
const
{
return
( f_len.size() ); }
196
198
[[nodiscard]] std::size_t
size
(
void
)
const
{
return
( f_n ); }
199
200
/*--------------------------------------------------------------------------*/
201
private
:
204
[[nodiscard]] std::uint32_t next( std::uint32_t v ,
unsigned
char
c )
const
;
205
207
void
counts(
void
)
const
;
208
209
static
constexpr
std::uint32_t none = ~std::uint32_t( 0 );
210
211
std::vector< std::size_t > f_len;
212
std::vector< std::uint32_t > f_link;
213
std::vector< std::vector< std::pair< unsigned char , std::uint32_t > > >
214
f_next;
215
std::vector< std::uint8_t > f_prefix;
216
std::uint32_t f_last = 0;
217
std::size_t f_n = 0;
218
mutable
std::vector< std::size_t > f_count;
219
220
};
// end( class SuffixAutomaton )
221
222
/*--------------------------------------------------------------------------*/
223
224
}
// end( namespace ADS )
225
226
/*--------------------------------------------------------------------------*/
227
/*-------------------------- IMPLEMENTATION --------------------------------*/
228
/*--------------------------------------------------------------------------*/
229
230
#include "ADS/string/impl/SuffixAutomaton.tpp"
231
232
/*--------------------------------------------------------------------------*/
233
234
#endif
/* SuffixAutomaton.h included */
235
236
/*--------------------------------------------------------------------------*/
237
/*----------------------- End File SuffixAutomaton.h -----------------------*/
238
/*--------------------------------------------------------------------------*/
Contract.h
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
ADS::SuffixAutomaton::distinctSubstrings
std::size_t distinctSubstrings(void) const
the number of the nonempty distinct substrings of ,
ADS::SuffixAutomaton::longestCommonSubstring
std::pair< std::size_t, std::size_t > longestCommonSubstring(std::string_view T) const
the length of a longest common substring of and , and where it ends in (one past its last byte),...
ADS::SuffixAutomaton::states
std::size_t states(void) const
the number of states
Definition
SuffixAutomaton.h:195
ADS::SuffixAutomaton::contains
bool contains(std::string_view P) const
whether is a substring of , by following from the start
ADS::SuffixAutomaton::occurrences
std::size_t occurrences(std::string_view P) const
the number of the occurrences of in ( for the empty )
ADS::SuffixAutomaton::extend
void extend(unsigned char c)
the automaton of from that of
ADS::SuffixAutomaton::SuffixAutomaton
SuffixAutomaton(std::string_view S)
the automaton of , by extend() on each of its bytes
ADS::SuffixAutomaton::size
std::size_t size(void) const
the length of
Definition
SuffixAutomaton.h:198
ADS::SuffixAutomaton::SuffixAutomaton
SuffixAutomaton(void)
the automaton of the empty string, the start state alone
ADS
Definition
ADT.h:96
ADS
string
SuffixAutomaton.h
Generated by
1.17.0