|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Suffix automaton (SAM) over byte alphabet. More...
#include <Suffix_Structures.H>
Classes | |
| struct | State |
| One automaton state. More... | |
Public Member Functions | |
| Suffix_Automaton () | |
| Construct an empty suffix automaton (SAM) with only the root state. | |
| Suffix_Automaton (const Suffix_Automaton &other)=default | |
| Copy the states of another automaton. | |
| Suffix_Automaton (Suffix_Automaton &&other) | |
| Take the states of another automaton, which is left empty, with the root state only, as built by default. | |
| Suffix_Automaton & | operator= (const Suffix_Automaton &other)=default |
| Copy the states of another automaton. | |
| Suffix_Automaton & | operator= (Suffix_Automaton &&other) noexcept |
| Exchange this automaton with another, which is left with the previous states of this one. | |
| void | swap (Suffix_Automaton &other) noexcept |
| Exchange in O(1) the states of this automaton and another. | |
| void | clear () |
| Reset the automaton to its initial empty state (root only). | |
| void | extend (const char ch) |
| Extend the SAM with a single character. | |
| void | build (const std::string_view text) |
| Build the SAM from an entire string. | |
| bool | contains (const std::string_view pattern) const |
Return true if pattern is a substring of the built text. | |
| size_t | distinct_substring_count () const |
| Count the number of distinct substrings in the built text. | |
| std::string | longest_common_substring (const std::string_view other) const |
Find the longest common substring between the built SAM text and other. | |
| size_t | state_count () const noexcept |
| Return the number of states in the SAM. | |
| const Array< State > & | states () const noexcept |
| Access the internal states array for testing/inspection. | |
Private Member Functions | |
| void | mark_terminals () |
| Traverse suffix links from last and mark all states as terminal. | |
Private Attributes | |
| Array< State > | states_ |
| int | last_ = 0 |
Suffix automaton (SAM) over byte alphabet.
Supports substring checks, distinct substring counting, and longest common substring against another string.
std::vector copies these objects instead of moving them: their move constructor is not noexcept, because it leaves the source empty and usable, which allocates, and std::vector moves only what cannot throw. The containers of Aleph do not copy them to grow: Array moves its items, and DynList and DynArray never relocate them. Definition at line 622 of file Suffix_Structures.H.
|
inline |
Construct an empty suffix automaton (SAM) with only the root state.
| None. |
Definition at line 663 of file Suffix_Structures.H.
References clear().
|
default |
Copy the states of another automaton.
| [in] | other | automaton to copy. |
| std::bad_alloc | if the states cannot be allocated. |
|
inline |
Take the states of another automaton, which is left empty, with the root state only, as built by default.
The implicit move took the states, the root among them, but copied the index of the last state: the moved-from automaton then read states that it no longer had.
| [in,out] | other | automaton to move from. |
| std::bad_alloc | if the root left to other cannot be allocated; other is then unchanged. |
other. Definition at line 687 of file Suffix_Structures.H.
References swap().
|
inline |
Build the SAM from an entire string.
| [in] | text | The input string to process. |
| None. |
Definition at line 798 of file Suffix_Structures.H.
References clear(), extend(), and mark_terminals().
Referenced by Aleph::longest_common_substring_sam(), main(), Moved_From_Case< Suffix_Automaton >::make(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and Moved_From_Case< Suffix_Automaton >::use().
|
inline |
Reset the automaton to its initial empty state (root only).
| None. |
Definition at line 725 of file Suffix_Structures.H.
References last_, and states_.
Referenced by Suffix_Automaton(), build(), and Moved_From_Case< Suffix_Automaton >::use().
|
inline |
Return true if pattern is a substring of the built text.
| [in] | pattern | The substring pattern to search for. |
pattern, false otherwise. | None. |
Definition at line 814 of file Suffix_Structures.H.
References Aleph::next(), and states_.
Referenced by main(), TEST(), TEST(), TEST(), TEST(), TEST(), and Moved_From_Case< Suffix_Automaton >::use().
|
inline |
Count the number of distinct substrings in the built text.
| None. |
Definition at line 833 of file Suffix_Structures.H.
References Aleph::Suffix_Automaton::State::len, Aleph::Suffix_Automaton::State::link, and states_.
Referenced by Moved_From_Case< Suffix_Automaton >::is_empty(), main(), TEST(), TEST(), TEST(), and Moved_From_Case< Suffix_Automaton >::use().
|
inline |
Extend the SAM with a single character.
| [in] | ch | The character to append to the current text representation. |
| None. |
Definition at line 742 of file Suffix_Structures.H.
References Aleph::and, last_, Aleph::Suffix_Automaton::State::len, Aleph::next(), and states_.
Referenced by build(), and Moved_From_Case< Suffix_Automaton >::use().
|
inline |
Find the longest common substring between the built SAM text and other.
| [in] | other | String to compare against the built SAM text. |
| None. |
Definition at line 854 of file Suffix_Structures.H.
References Aleph::and, Aleph::next(), and states_.
Referenced by Aleph::longest_common_substring_sam(), main(), TEST(), TEST(), and Moved_From_Case< Suffix_Automaton >::use().
|
inlineprivate |
Traverse suffix links from last and mark all states as terminal.
| None. |
Definition at line 647 of file Suffix_Structures.H.
References last_, and states_.
Referenced by build().
|
default |
Copy the states of another automaton.
| [in] | other | automaton to copy. |
| std::bad_alloc | if the states cannot be allocated. |
|
inlinenoexcept |
Exchange this automaton with another, which is left with the previous states of this one.
| [in,out] | other | automaton to move from. |
Definition at line 705 of file Suffix_Structures.H.
References swap().
|
inlinenoexcept |
Return the number of states in the SAM.
| None. |
Definition at line 902 of file Suffix_Structures.H.
References states_.
Referenced by Moved_From_Case< Suffix_Automaton >::is_empty(), main(), TEST(), and Moved_From_Case< Suffix_Automaton >::use().
Access the internal states array for testing/inspection.
| None. |
Definition at line 913 of file Suffix_Structures.H.
References states_.
Referenced by TEST(), and Moved_From_Case< Suffix_Automaton >::use().
|
inlinenoexcept |
Exchange in O(1) the states of this automaton and another.
| [in,out] | other | automaton to exchange with. |
Definition at line 714 of file Suffix_Structures.H.
References last_, and states_.
Referenced by Suffix_Automaton(), and operator=().
|
private |
Definition at line 642 of file Suffix_Structures.H.
Referenced by clear(), extend(), mark_terminals(), and swap().
Definition at line 641 of file Suffix_Structures.H.
Referenced by clear(), contains(), distinct_substring_count(), extend(), longest_common_substring(), mark_terminals(), state_count(), states(), and swap().