pub struct SuffixArray { /* private fields */ }Expand description
A suffix array built from a text.
The suffix array stores the starting positions of all suffixes of the input text, sorted in lexicographic order. This enables efficient substring search via binary search.
Implementations§
Source§impl SuffixArray
impl SuffixArray
Sourcepub fn build(text: &[u8]) -> Self
pub fn build(text: &[u8]) -> Self
Build a suffix array from the given text using the SA-IS algorithm.
Appends a sentinel character (value 0, lexicographically smallest) to ensure correct suffix ordering.
Time complexity: O(n) where n is the length of the text.
§Example
use cyanea_seq::suffix::SuffixArray;
let sa = SuffixArray::build(b"banana");
let positions = sa.search(b"banana", b"ana");
assert_eq!(positions.len(), 2);Sourcepub fn search(&self, text: &[u8], pattern: &[u8]) -> Vec<usize>
pub fn search(&self, text: &[u8], pattern: &[u8]) -> Vec<usize>
Search for all occurrences of pattern in text.
The text must be the same text used to build the suffix array
(without the sentinel). Returns positions in arbitrary order.
Time complexity: O(m log n) where m is the pattern length and n is the text length.
Trait Implementations§
Source§impl Clone for SuffixArray
impl Clone for SuffixArray
Source§fn clone(&self) -> SuffixArray
fn clone(&self) -> SuffixArray
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for SuffixArray
impl RefUnwindSafe for SuffixArray
impl Send for SuffixArray
impl Sync for SuffixArray
impl Unpin for SuffixArray
impl UnsafeUnpin for SuffixArray
impl UnwindSafe for SuffixArray
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more