Fast realization of suffix array and suffix tree for substring search, longest common prefix array (lcp array).
The current implementation builds suffix structures using bytes and does not decode the string before or during construction in Unicode. But if Unicode string is normalized before construction and search, then structures support Unicode (because all byte sequences are decoded unambiguously). Also search and lcp returns indexes as in byte array but not in Unicode decoded string.
SuffixTree ```rust use suff_collections::{array::, tree::, lcp::*};
// let word = "Some word"; let word: &str = "Some word\0"; let find: &str = "word";
// construct suffix tree let st: SuffixTree = SuffixTree::new(word);
// finds the entry position of the line 'find' in 'word'
let res: Option
// construct lcp
// lcp[i] = maxpref(sa[i], sa[i - 1]) && lcp.len() == sa.len()
// let lcp: LCP
// convert suffix tree to suffix array
// let sa = SuffixArray::
let mut buff = String::new(); SuffixTree::new("mississippi") .to_graphviz(&mut buff).unwrap(); println!("{}", &buff); ``` SuffixTree for the word "mississippi"
SuffixArray ```rust use suff_collections::{array::, tree::, lcp::*};
// let word = "Some word"; let word: &str = "Some word\0"; let find: &str = "word";
// construct suffix array
// let sa = SuffixArray::
// construct lcp
// lcp[i] = max_pref(sa[i], sa[i - 1]) && lcp.len() == sa.len()
let lcp: LCP
// finds the entry position of the line 'find' in 'word'
// O(|find| * log(|word|))
let res: Option
// finds all the entry position of the line 'find' in 'word' // O(|find| * log(|word|)) let resall: &[usize] = sa.findall(find);
// finds the entry position of the line 'find' in 'word'
// O(|word|)
let res: Option
// finds all the entry position of the line 'find' in 'word' // O(|word|) let resall: &[usize] = sa.findall_big(&sa.lcp(), find);
// convert suffix array to suffix tree let st = SuffixTree::from(sa);
let word = "mississippi";
let sa = SuffixArray::
SuffixArray and lcp for the word "mississippi"
LCP index suffixe's
0 11
0 10 i
1 7 ippi
1 4 issippi
4 1 ississippi
0 0 mississippi
0 9 pi
1 8 ppi
0 6 sippi
2 3 sissippi
1 5 ssippi
3 2 ssissippi
All construction and search work for O(n). For the suffix tree implementation the Ukkonen algorithm is taken and for the suffix array implementation the SA-IS algorithm is taken.