117#ifndef __ADS_SuffixTree
118 #define __ADS_SuffixTree
132#include <string_view>
154 static constexpr std::size_t
npos = std::numeric_limits< std::size_t >::max();
173 std::map< std::size_t , std::size_t >
child;
229 [[nodiscard]] std::size_t
root(
void )
const {
return( 0 ); }
233 [[nodiscard]]
const Node &
node( std::size_t u )
const;
238 [[nodiscard]] std::size_t
leaf( std::size_t i )
const;
243 [[nodiscard]] std::size_t
symbol( std::size_t i )
const;
266 [[nodiscard]] std::size_t
locus( std::string_view P )
const;
273 [[nodiscard]] std::size_t
count( std::string_view P )
const;
290 [[nodiscard]] std::vector< std::size_t >
locate( std::string_view P )
const;
307 [[nodiscard]] std::size_t
lca( std::size_t u , std::size_t v )
const;
325 [[nodiscard]] std::size_t
lce( std::size_t i , std::size_t j )
const;
350 [[nodiscard]] std::pair< std::vector< std::size_t > ,
351 std::vector< std::size_t > >
355 [[nodiscard]] std::vector< std::size_t >
preorder(
void )
const;
358 [[nodiscard]] std::size_t
size(
void )
const {
return( f_N.size() ); }
386 void construct(
const Symbols & T , std::size_t K ,
Build b );
387 void buildNaive(
void );
388 void buildMcCreight(
void );
389 void buildFromSuffixArray(
const Symbols & T , std::size_t K );
393 std::size_t newNode( std::size_t pos , std::size_t depth ,
394 std::size_t parent );
397 std::size_t attachLeaf( std::size_t u , std::size_t i );
401 std::size_t split( std::size_t u , std::size_t c , std::size_t d );
404 [[nodiscard]]
bool valid(
void )
const;
407 std::vector< Node > f_N;
408 std::vector< std::size_t > f_leaf;
409 std::vector< std::size_t > f_E;
410 std::vector< std::size_t > f_first;
423#include "ADS/string/impl/SuffixTree.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The range minimum query, beyond the book: given an array of items of an ordered universe,...
The suffix array of a text of symbols, beyond the book: is the starting place of the -th smallest ...
the range minima of an array whose adjacent items differ by 1
Definition RangeMinimum.h:238
const Node & const_reference
a node
Definition SuffixTree.h:367
std::ptrdiff_t difference_type
a difference of names
Definition SuffixTree.h:366
std::size_t locus(const Symbols &P) const
the locus of locus() above, of an integer pattern
std::size_t size(void) const
the number of nodes
Definition SuffixTree.h:358
const_iterator cend(void) const
one past the last node
Definition SuffixTree.h:380
std::vector< std::size_t > preorder(void) const
the nodes in preorder, the children by increasing first symbol
std::pair< std::vector< std::size_t >, std::vector< std::size_t > > toSuffixArray(void) const
and of , by a visit in order
SuffixTree(std::string_view T, Build b=Build::mcCreight)
the suffix tree of the bytes of , built as b says
SuffixTree(void)=default
the tree of no text, with no node
const_iterator begin(void) const
the root
Definition SuffixTree.h:374
std::size_t symbol(std::size_t i) const
the symbol at the place of as stored: the symbols of plus 1, and 0 for the terminator at
std::size_t size_type
the type of the names
Definition SuffixTree.h:365
std::size_t root(void) const
the root, the node 0
Definition SuffixTree.h:229
std::size_t leaf(std::size_t i) const
the leaf of the suffix , the terminator being the suffix
std::size_t locus(std::string_view P) const
the extended locus of , or npos if does not occur
const_iterator iterator
on the nodes
Definition SuffixTree.h:371
SuffixTree(const Symbols &T, std::size_t K, Build b=Build::mcCreight)
the suffix tree of an integer text, built as the one of the bytes above
const_iterator cbegin(void) const
the root
Definition SuffixTree.h:378
const Node & node(std::size_t u) const
the node
const_iterator end(void) const
one past the last node
Definition SuffixTree.h:376
std::size_t textSize(void) const
the length of , without the terminator
std::size_t lce(std::size_t i, std::size_t j) const
the length of the longest common prefix of the suffixes and of
std::vector< Node >::const_iterator const_iterator
a constant iterator on the nodes
Definition SuffixTree.h:370
std::vector< std::size_t > locate(std::string_view P) const
the places of the occurrences of , in lexicographic order of their suffixes; the empty pattern at the...
Node value_type
a node
Definition SuffixTree.h:364
const_reference reference
a node
Definition SuffixTree.h:368
Build
the construction
Definition SuffixTree.h:157
@ mcCreight
the suffix links of McCreight
Definition SuffixTree.h:159
@ naive
each suffix by a walk down from the root
Definition SuffixTree.h:158
static constexpr std::size_t npos
no node, no suffix
Definition SuffixTree.h:154
std::size_t lca(std::size_t u, std::size_t v) const
the lowest common ancestor of and ,
std::size_t count(std::string_view P) const
the number of occurrences of , the leaves below its locus (the terminator left out)
std::vector< std::size_t > Symbols
a text on an integer alphabet
Definition SuffixArray.h:186
std::vector< I > suffixArray(std::string_view T)
the suffix array of the bytes of , by SA-IS on integers I (32 or 64 bits, unsigned)
a node ; the edge into it is labeled by the symbols of from pos plus the depth of the parent to pos ...
Definition SuffixTree.h:167
std::size_t suffix
the suffix of a leaf, npos inside
Definition SuffixTree.h:171
std::size_t parent
npos at the root
Definition SuffixTree.h:170
std::size_t depth
the string depth
Definition SuffixTree.h:169
std::map< std::size_t, std::size_t > child
by first symbol
Definition SuffixTree.h:173
std::size_t leaves
the leaves below
Definition SuffixTree.h:172
std::size_t pos
where occurs once
Definition SuffixTree.h:168