6 releases
0.2.2 | Jan 7, 2024 |
---|---|
0.2.1 | Jan 6, 2024 |
0.1.2 | Jan 5, 2024 |
#703 in Algorithms
11KB
178 lines
KMPM
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
Usage
Create new rust project,and add kmpm dependencies to Cargo.toml file.
Cargo.toml
[dependencies]
kmpm="0.2"
Code Example
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