Crates.io | kmpm |
lib.rs | kmpm |
version | 0.2.2 |
source | src |
created_at | 2024-01-05 09:36:35.213359 |
updated_at | 2024-01-07 15:00:00.062996 |
description | KMP(Knuth-Morris-Pratt algorithm) method library |
homepage | |
repository | https://github.com/Tom-game-project/kmpm.git |
max_upload_size | |
id | 1089526 |
size | 11,842 |
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