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

Function search2

src/strings/brute_force.rs:27–48  ·  view source on GitHub ↗
(pat: &str, txt: &str)

Source from the content-addressed store, hash-verified

25
26#[deprecated(note = "brute force search used by benchmark, use KMP in production")]
27pub fn search2(pat: &str, txt: &str) -> Option<usize> {
28 let M = pat.len();
29 let N = txt.len();
30 let mut i = 0;
31 let mut j = 0;
32 while i < N && j < M {
33 let ic = common::util::byte_at(txt, i);
34 let jc = common::util::byte_at(pat, j);
35 if ic == jc {
36 j += 1;
37 } else {
38 i -= j;
39 j = 0;
40 }
41 i += 1;
42 }
43 if j == M {
44 Some(i - M)
45 } else {
46 None
47 }
48}

Callers

nothing calls this directly

Calls 2

byte_atFunction · 0.85
lenMethod · 0.45

Tested by

no test coverage detected