https://github.com/remierichards/kmpsearch-rs
Rust implementation of Knuth-Morris-Pratt Searching
https://github.com/remierichards/kmpsearch-rs
kmp-algorithm rust-library searching-algorithms string-search
Last synced: about 2 months ago
JSON representation
Rust implementation of Knuth-Morris-Pratt Searching
- Host: GitHub
- URL: https://github.com/remierichards/kmpsearch-rs
- Owner: RemieRichards
- License: mit
- Created: 2019-02-17T19:10:58.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-02-23T15:37:01.000Z (over 6 years ago)
- Last Synced: 2024-10-08T17:14:13.136Z (9 months ago)
- Topics: kmp-algorithm, rust-library, searching-algorithms, string-search
- Language: Rust
- Size: 5.86 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# kmpsearch
Allows searching for bytes or strings within byte slices or strings, using the Knuth Morris Pratt algorithm.
KMP runs in O(n+h) time broken down as O(n) preparation, O(h) matching, where n is the length of the needle and h the length of the haystack.Special thanks to PJB3005 for the help with AsRef which makes this library nicer to use.
This is my first rust crate, so any feedback is welcome.
Pull requests are accepted on github.## Usage:
Matching strings in strings
```rust
if "Hello World!".contains_needle("World") {
println!("Matches!");
} else {
println!("Doesn't match!");
}
```Matching bytes in bytes
```rust
if b"DEADBEEF".contains_needle(b"BEEF") {
println!("Matches!");
} else {
println!("Doesn't match!");
}
```Getting all the indexes of a string in another string
```rust
let res = "That fox is a cool fox, he knows magic".indexesof_needle("fox");
assert_eq!(res.unwrap(), vec![5, 19]);
```