A method for finding all common strings. Check it on Crates.io.
The algorithm uses a two-dimensional trie to find the fragments. The vertical dimension is a standard suffix trie; nodes at the end of each suffix are also linked horizontally.
Use get_substrings to get the common substrings in a list of strings.
use common_substrings::get_substrings;
let input_strings = vec!["java", "javascript", "typescript", "coffeescript", "coffee"];
let result_substrings = get_substrings(input_strings, 2, 3);This produces results such as:
Substring(sources: {2, 3}, name: escript, weight: 14)
Substring(sources: {1, 0}, name: java, weight: 8)
Substring(sources: {4, 3}, name: coffee, weight: 12)input— The input strings.min_occurrences— The minimum number of input strings containing a result.min_length— The minimum result length, measured in Unicode scalar values.
Both thresholds must be positive. When min_occurrences exceeds the input size, the result is empty.
The minimum supported Rust version is 1.86.
Explanation here
Apache-2.0