kmpm

Crates.iokmpm
lib.rskmpm
version0.2.2
sourcesrc
created_at2024-01-05 09:36:35.213359
updated_at2024-01-07 15:00:00.062996
descriptionKMP(Knuth-Morris-Pratt algorithm) method library
homepage
repositoryhttps://github.com/Tom-game-project/kmpm.git
max_upload_size
id1089526
size11,842
Tom0427 (Tom-game-project)

documentation

https://docs.rs/kmpm/latest/kmpm/

README

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

Commit count: 0

cargo fmt