KMPM (Knuth-Morris-Pratt algorithm) library. KMPM is one of effective character query algorithm.
If the length of the text is n and the length of the pattern is m, the KMP algorithm processes in O(n+m) time
Create new rust project,and add kmpm dependencies to Cargo.toml file.
Cargo.toml
[dependencies]
kmpm="0.2"
main.rs
use kmpm::kmpm_str;
fn main(){
let text = "hello world !";
let pattern = "world";
let ctr = kmpm_str(text, pattern);
match ctr {
Some(cursor)=>{
println!("matched index {}",cursor)
}
None=>{
println!("\"{}\" does not match",pattern);
}
}
}
matched index 6
========================
"hello world !"
"world"
------^^^^^
|
#6