6 releases

0.2.2 Jan 7, 2024
0.2.1 Jan 6, 2024
0.1.2 Jan 5, 2024

#611 in Algorithms

Download history 32/week @ 2024-01-01 1/week @ 2024-02-19 7/week @ 2024-02-26 92/week @ 2024-04-01

92 downloads per month

MIT license

11KB
178 lines

KMPM

githubcrates-iodocs-rs

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

License

MIT

No runtime deps