3#ifndef STEP20_LONGEST_REPEATED_SUBSTRING_HPP
4#define STEP20_LONGEST_REPEATED_SUBSTRING_HPP
19 auto first = arr.
data();
20 auto last = first + arr.size();
21 auto result = std::basic_string_view{last, last};
22 auto lcp = arr.lcp_array();
23 auto max = std::ranges::max_element(lcp);
24 if (max != lcp.end() && *max > 0) {
25 auto pos = arr[max - lcp.begin()];
26 result = std::basic_string_view{first + pos, first + pos + *max};
39 -> std::basic_string_view<
typename suffix_tree<Ts...>::value_type>
41 auto first = tree.
data();
42 auto last = first + tree.size();
43 auto result = std::basic_string_view{last, last};
44 if (
auto start = tree.find(result))
45 for (
auto edge : tree.depth_first_search(*start)) {
46 if (tree.leaf(edge.child_node) || edge.labels_len <= result.size())
48 auto labels = tree.labels(edge);
49 result = std::basic_string_view{first + labels.first,
Kasai's algorithm for constructing longest common prefix array.
Definition suffix_array.hpp:122
const Char * data() const
Definition suffix_array.hpp:27
Ukkonen's online algorithm for constructing suffix tree.
Definition suffix_tree.hpp:24
const Char * data() const
Definition suffix_tree.hpp:28
Definition edit_distance.hpp:11
auto longest_repeated_substring(const enhanced_suffix_array< Ts... > &arr) -> std::basic_string_view< typename enhanced_suffix_array< Ts... >::value_type >
Find the longest substring that occurs at least twice.
Definition longest_repeated_substring.hpp:16