MCPcopy Create free account
hub / github.com/douchuan/algorithm / search

Method search

src/strings/kmp.rs:35–50  ·  view source on GitHub ↗

Returns the index of the first occurrence of the pattern string in the text string.

(&self, txt: &str)

Source from the content-addressed store, hash-verified

33 /// Returns the index of the first occurrence of the pattern string
34 /// in the text string.
35 pub fn search(&self, txt: &str) -> Option<usize> {
36 let dfa = self.dfa.as_slice();
37 let M = self.M;
38 let N = txt.len();
39 let mut i = 0;
40 let mut j = 0;
41 while i < N && j < M {
42 j = dfa[byte_at(txt, i)][j];
43 i += 1;
44 }
45 if j == M {
46 Some(i - M)
47 } else {
48 None
49 }
50 }
51}
52
53impl From<&str> for KMP {

Callers 1

sub_search_kmpFunction · 0.80

Calls 2

byte_atFunction · 0.85
lenMethod · 0.45

Tested by

no test coverage detected