pub(crate) fn rfind_with(
    nhash: &NeedleHash,
    mut haystack: &[u8],
    needle: &[u8],
) -> Option<usize> {
    if haystack.len() < needle.len() {
        return None;
    }
    let mut hash =
        Hash::from_bytes_rev(&haystack[haystack.len() - needle.len()..]);
    loop {
        if nhash.eq(hash) && is_suffix(haystack, needle) {
            return Some(haystack.len() - needle.len());
        }
        if needle.len() >= haystack.len() {
            return None;
        }
        hash.roll(
            &nhash,
            haystack[haystack.len() - 1],
            haystack[haystack.len() - needle.len() - 1],
        );
        haystack = &haystack[..haystack.len() - 1];
    }
}
/// Search for the last occurrence of needle in haystack using Rabin-Karp with
/// a pre-computed needle hash.
Search for the last occurrence of needle in haystack using Rabin-Karp with
a pre-computed needle hash.
Search for the last occurrence of needle in haystack using Rabin - Karp with a pre - computed needle hash .
pub(crate) fn rfind_with(
    nhash: &NeedleHash,
    mut haystack: &[u8],
    needle: &[u8],
) -> Option<usize> {
    if haystack.len() < needle.len() {
        return None;
    }
    let mut hash =
        Hash::from_bytes_rev(&haystack[haystack.len() - needle.len()..]);
    loop {
        if nhash.eq(hash) && is_suffix(haystack, needle) {
            return Some(haystack.len() - needle.len());
        }
        if needle.len() >= haystack.len() {
            return None;
        }
        hash.roll(
            &nhash,
            haystack[haystack.len() - 1],
            haystack[haystack.len() - needle.len() - 1],
        );
        haystack = &haystack[..haystack.len() - 1];
    }
}
pub ( crate ) fn rfind_with ( nhash : & NeedleHash , mut haystack : & [ u8 ] , needle : & [ u8 ] , ) -> Option < usize > { if haystack . len ( ) < needle . len ( ) { return None ; } let mut hash = Hash :: from_bytes_rev ( & haystack [ haystack . len ( ) - needle . len ( ) .. ] ) ; loop { if nhash . eq ( hash ) && is_suffix ( haystack , needle ) { return Some ( haystack . len ( ) - needle . len ( ) ) ; } if needle . len ( ) >= haystack . len ( ) { return None ; } hash . roll ( & nhash , haystack [ haystack . len ( ) - 1 ] , haystack [ haystack . len ( ) - needle . len ( ) - 1 ] , ) ; haystack = & haystack [ .. haystack . len ( ) - 1 ] ; } }
Search for the last occurrence of needle in haystack using Rabin-Karp with
a pre-computed needle hash.
Search for the last 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]