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

Function search1

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

Source from the content-addressed store, hash-verified

3
4#[deprecated(note = "brute force search used by benchmark, use KMP in production")]
5pub fn search1(pat: &str, txt: &str) -> Option<usize> {
6 let M = pat.len();
7 let N = txt.len();
8 for i in 0..=(N - M) {
9 let mut j = 0;
10 while j < M {
11 let ic = common::util::byte_at(txt, i + j);
12 let jc = common::util::byte_at(pat, j);
13 if ic != jc {
14 break;
15 }
16 j += 1;
17 }
18 if j == M {
19 return Some(i);
20 }
21 }
22
23 None
24}
25
26#[deprecated(note = "brute force search used by benchmark, use KMP in production")]
27pub fn search2(pat: &str, txt: &str) -> Option<usize> {

Callers 1

sub_search_brute_forceFunction · 0.85

Calls 2

byte_atFunction · 0.85
lenMethod · 0.45

Tested by

no test coverage detected