pub(crate) fn find_with(
    nhash: &NeedleHash,
    mut haystack: &[u8],
    needle: &[u8],
) -> Option<usize> {
    if haystack.len() < needle.len() {
        return None;
    }
    let start = haystack.as_ptr() as usize;
    let mut hash = Hash::from_bytes_fwd(&haystack[..needle.len()]);
    // N.B. I've experimented with unrolling this loop, but couldn't realize
    // any obvious gains.
    loop {
        if nhash.eq(hash) && is_prefix(haystack, needle) {
            return Some(haystack.as_ptr() as usize - start);
        }
        if needle.len() >= haystack.len() {
            return None;
        }
        hash.roll(&nhash, haystack[0], haystack[needle.len()]);
        haystack = &haystack[1..];
    }
}
/// Search for the first occurrence of needle in haystack using Rabin-Karp with
/// a pre-computed needle hash.
Search for the first occurrence of needle in haystack using Rabin-Karp with
a pre-computed needle hash.
Search for the first occurrence of needle in haystack using Rabin - Karp with a pre - computed needle hash .
pub(crate) fn find_with(
    nhash: &NeedleHash,
    mut haystack: &[u8],
    needle: &[u8],
) -> Option<usize> {
    if haystack.len() < needle.len() {
        return None;
    }
    let start = haystack.as_ptr() as usize;
    let mut hash = Hash::from_bytes_fwd(&haystack[..needle.len()]);
    // N.B. I've experimented with unrolling this loop, but couldn't realize
    // any obvious gains.
    loop {
        if nhash.eq(hash) && is_prefix(haystack, needle) {
            return Some(haystack.as_ptr() as usize - start);
        }
        if needle.len() >= haystack.len() {
            return None;
        }
        hash.roll(&nhash, haystack[0], haystack[needle.len()]);
        haystack = &haystack[1..];
    }
}
pub ( crate ) fn find_with ( nhash : & NeedleHash , mut haystack : & [ u8 ] , needle : & [ u8 ] , ) -> Option < usize > { if haystack . len ( ) < needle . len ( ) { return None ; } let start = haystack . as_ptr ( ) as usize ; let mut hash = Hash :: from_bytes_fwd ( & haystack [ .. needle . len ( ) ] ) ; // N.B. I've experimented with unrolling this loop, but couldn't realize // any obvious gains. loop { if nhash . eq ( hash ) && is_prefix ( haystack , needle ) { return Some ( haystack . as_ptr ( ) as usize - start ) ; } if needle . len ( ) >= haystack . len ( ) { return None ; } hash . roll ( & nhash , haystack [ 0 ] , haystack [ needle . len ( ) ] ) ; haystack = & haystack [ 1 .. ] ; } }
Search for the first occurrence of needle in haystack using Rabin-Karp with
a pre-computed needle hash.
Search for the first occurrence of needle in haystack using Rabin - Karp with a pre - computed needle hash .
nhash
&NeedleHash
haystack
&[u8]
needle
&[u8]
nhash
&NeedleHash
haystack
&[u8]
needle
&[u8]