|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Naive compressed suffix tree (didactic implementation). More...
#include <Suffix_Structures.H>
Classes | |
| struct | Node |
| One tree node. More... | |
Public Member Functions | |
| Naive_Suffix_Tree (const std::string_view text="") | |
| Construct a naive suffix tree. | |
| void | build (const std::string_view text) |
Build or rebuild the suffix tree for text. | |
| bool | contains (const std::string_view pattern) const |
| Return true if the pattern appears in the text. | |
| Array< size_t > | find_all (const std::string_view pattern) const |
| Return all occurrences of a pattern. | |
| size_t | node_count () const noexcept |
| Return the number of nodes in the tree. | |
| size_t | text_size () const noexcept |
| Return the text size (without terminal marker). | |
| const Array< Node > & | nodes () const noexcept |
| Return the internal node array for inspection/debugging. | |
Static Public Attributes | |
| static constexpr size_t | npos = std::numeric_limits<size_t>::max() |
Private Member Functions | |
| size_t | create_node (const size_t start, const size_t end, const size_t parent, const size_t suffix_index) |
| size_t | find_child_by_first_char (const size_t node, const char c) const |
| void | replace_child (const size_t parent, const size_t old_child, const size_t new_child) |
| void | insert_suffix (const size_t suffix_start) |
| void | collect_leaf_suffixes (const size_t node, Array< size_t > &out) const |
Static Private Member Functions | |
| static char | choose_terminal (const std::string_view s) |
Private Attributes | |
| std::string | text_ |
| size_t | original_size_ = 0 |
| Array< Node > | nodes_ |
Naive compressed suffix tree (didactic implementation).
This is intentionally simple and educational (O(n^2) construction), not Ukkonen's linear-time algorithm.
Definition at line 252 of file Suffix_Structures.H.
|
inlineexplicit |
Construct a naive suffix tree.
| [in] | text | The text to build the tree from. If empty, the tree will only contain the terminal character. |
| std::domain_error | If all 256 byte values are present in text, leaving no unique sentinel character available. |
Definition at line 412 of file Suffix_Structures.H.
References build(), and Aleph::divide_and_conquer_partition_dp().
Build or rebuild the suffix tree for text.
| [in] | text | The text to build the tree from. |
| std::domain_error | If all 256 byte values are present in text, leaving no unique sentinel character available. |
Definition at line 424 of file Suffix_Structures.H.
References choose_terminal(), Aleph::divide_and_conquer_partition_dp(), insert_suffix(), nodes_, original_size_, and text_.
Referenced by Naive_Suffix_Tree().
|
inlinestaticprivate |
Definition at line 275 of file Suffix_Structures.H.
References ah_domain_error, and Aleph::divide_and_conquer_partition_dp().
Referenced by build().
|
inlineprivate |
Definition at line 382 of file Suffix_Structures.H.
References Aleph::Array< T >::append(), Aleph::divide_and_conquer_partition_dp(), Aleph::Array< T >::is_empty(), nodes_, npos, original_size_, and Aleph::Array< T >::remove_last().
Referenced by find_all().
Return true if the pattern appears in the text.
| [in] | pattern | The substring pattern to search for. |
pattern is found in the text, false otherwise. If pattern is empty, returns true. | None. |
Definition at line 448 of file Suffix_Structures.H.
References Aleph::and, Aleph::divide_and_conquer_partition_dp(), find_child_by_first_char(), k, nodes_, npos, and text_.
|
inlineprivate |
Definition at line 293 of file Suffix_Structures.H.
References Aleph::Naive_Suffix_Tree::Node::end, nodes_, Aleph::Naive_Suffix_Tree::Node::parent, Aleph::Naive_Suffix_Tree::Node::start, and Aleph::Naive_Suffix_Tree::Node::suffix_index.
Referenced by insert_suffix().
Return all occurrences of a pattern.
| [in] | pattern | The substring pattern to search for. |
pattern in the text, sorted in ascending order. Returns an empty array if no occurrences are found. pattern is empty, all positions [0, text.size()] are returned. | None. |
Definition at line 500 of file Suffix_Structures.H.
References Aleph::suffix_structures_detail::all_positions(), Aleph::and, collect_leaf_suffixes(), Aleph::divide_and_conquer_partition_dp(), find_child_by_first_char(), k, nodes_, npos, original_size_, Aleph::suffix_structures_detail::sort_matches(), and text_.
|
inlineprivate |
Definition at line 307 of file Suffix_Structures.H.
References nodes_, npos, Aleph::Array< T >::size(), and text_.
Referenced by contains(), find_all(), and insert_suffix().
Definition at line 330 of file Suffix_Structures.H.
References Aleph::and, create_node(), Aleph::divide_and_conquer_partition_dp(), find_child_by_first_char(), k, nodes_, npos, replace_child(), Aleph::split(), and text_.
Referenced by build().
|
inlinenoexcept |
Return the number of nodes in the tree.
| None. |
Definition at line 551 of file Suffix_Structures.H.
References nodes_.
Return the internal node array for inspection/debugging.
| None. |
Definition at line 574 of file Suffix_Structures.H.
References nodes_.
Referenced by TEST().
|
inlineprivate |
Definition at line 318 of file Suffix_Structures.H.
References Aleph::divide_and_conquer_partition_dp(), and nodes_.
Referenced by insert_suffix().
|
inlinenoexcept |
Return the text size (without terminal marker).
original_size_ member. | None. |
Definition at line 563 of file Suffix_Structures.H.
References original_size_.
Referenced by TEST().
Definition at line 273 of file Suffix_Structures.H.
Referenced by build(), collect_leaf_suffixes(), contains(), create_node(), find_all(), find_child_by_first_char(), insert_suffix(), node_count(), nodes(), and replace_child().
|
staticconstexpr |
Definition at line 255 of file Suffix_Structures.H.
Referenced by collect_leaf_suffixes(), contains(), find_all(), find_child_by_first_char(), and insert_suffix().
|
private |
Definition at line 272 of file Suffix_Structures.H.
Referenced by build(), collect_leaf_suffixes(), find_all(), and text_size().
|
private |
Definition at line 271 of file Suffix_Structures.H.
Referenced by build(), contains(), find_all(), find_child_by_first_char(), and insert_suffix().