fn new(
            seed: &PrefilterTestSeed,
            rare1i: usize,
            rare2i: usize,
            haystack_len: usize,
            needle_len: usize,
            output: Option<usize>,
        ) -> Option<PrefilterTest> {
            let mut rare1i: u8 = rare1i.try_into().unwrap();
            let mut rare2i: u8 = rare2i.try_into().unwrap();
            // The '#' byte is never used in a haystack (unless we're expecting
            // a match), while the '@' byte is never used in a needle.
            let mut haystack = vec![b'@'; haystack_len];
            let mut needle = vec![b'#'; needle_len];
            needle[0] = seed.first;
            needle[rare1i as usize] = seed.rare1;
            needle[rare2i as usize] = seed.rare2;
            // If we're expecting a match, then make sure the needle occurs
            // in the haystack at the expected position.
            if let Some(i) = output {
                haystack[i..i + needle.len()].copy_from_slice(&needle);
            }
            // If the operations above lead to rare offsets pointing to the
            // non-first occurrence of a byte, then adjust it. This might lead
            // to redundant tests, but it's simpler than trying to change the
            // generation process I think.
            if let Some(i) = crate::memchr(seed.rare1, &needle) {
                rare1i = u8::try_from(i).unwrap();
            }
            if let Some(i) = crate::memchr(seed.rare2, &needle) {
                rare2i = u8::try_from(i).unwrap();
            }
            let ninfo = NeedleInfo {
                rarebytes: RareNeedleBytes::new(rare1i, rare2i),
                nhash: rabinkarp::NeedleHash::forward(&needle),
            };
            Some(PrefilterTest { ninfo, haystack, needle, output })
        }
/// Create a new prefilter test from a seed and some chose offsets to
/// rare bytes in the seed's needle.
///
/// If a valid test could not be constructed, then None is returned.
/// (Currently, we take the approach of massaging tests to be valid
/// instead of rejecting them outright.)
Create a new prefilter test from a seed and some chose offsets to
rare bytes in the seed's needle.

If a valid test could not be constructed, then None is returned.
(Currently, we take the approach of massaging tests to be valid
instead of rejecting them outright.)
Create a new prefilter test from a seed and some chose offsets to rare bytes in the seed ' s needle . If a valid test could not be constructed then None is returned . ( Currently we take the approach of massaging tests to be valid instead of rejecting them outright . )
fn new(
            seed: &PrefilterTestSeed,
            rare1i: usize,
            rare2i: usize,
            haystack_len: usize,
            needle_len: usize,
            output: Option<usize>,
        ) -> Option<PrefilterTest> {
            let mut rare1i: u8 = rare1i.try_into().unwrap();
            let mut rare2i: u8 = rare2i.try_into().unwrap();
            // The '#' byte is never used in a haystack (unless we're expecting
            // a match), while the '@' byte is never used in a needle.
            let mut haystack = vec![b'@'; haystack_len];
            let mut needle = vec![b'#'; needle_len];
            needle[0] = seed.first;
            needle[rare1i as usize] = seed.rare1;
            needle[rare2i as usize] = seed.rare2;
            // If we're expecting a match, then make sure the needle occurs
            // in the haystack at the expected position.
            if let Some(i) = output {
                haystack[i..i + needle.len()].copy_from_slice(&needle);
            }
            // If the operations above lead to rare offsets pointing to the
            // non-first occurrence of a byte, then adjust it. This might lead
            // to redundant tests, but it's simpler than trying to change the
            // generation process I think.
            if let Some(i) = crate::memchr(seed.rare1, &needle) {
                rare1i = u8::try_from(i).unwrap();
            }
            if let Some(i) = crate::memchr(seed.rare2, &needle) {
                rare2i = u8::try_from(i).unwrap();
            }
            let ninfo = NeedleInfo {
                rarebytes: RareNeedleBytes::new(rare1i, rare2i),
                nhash: rabinkarp::NeedleHash::forward(&needle),
            };
            Some(PrefilterTest { ninfo, haystack, needle, output })
        }
fn new ( seed : & PrefilterTestSeed , rare1i : usize , rare2i : usize , haystack_len : usize , needle_len : usize , output : Option < usize > , ) -> Option < PrefilterTest > { let mut rare1i : u8 = rare1i . try_into ( ) . unwrap ( ) ; let mut rare2i : u8 = rare2i . try_into ( ) . unwrap ( ) ; // The '#' byte is never used in a haystack (unless we're expecting // a match), while the '@' byte is never used in a needle. let mut haystack = vec ! [ b'@' haystack_len ] ; let mut needle = vec ! [ b'#' needle_len ] ; needle [ 0 ] = seed . first ; needle [ rare1i as usize ] = seed . rare1 ; needle [ rare2i as usize ] = seed . rare2 ; // If we're expecting a match, then make sure the needle occurs // in the haystack at the expected position. if let Some ( i ) = output { haystack [ i .. i + needle . len ( ) ] . copy_from_slice ( & needle ) ; } // If the operations above lead to rare offsets pointing to the // non-first occurrence of a byte, then adjust it. This might lead // to redundant tests, but it's simpler than trying to change the // generation process I think. if let Some ( i ) = crate :: memchr ( seed . rare1 , & needle ) { rare1i = u8 :: try_from ( i ) . unwrap ( ) ; } if let Some ( i ) = crate :: memchr ( seed . rare2 , & needle ) { rare2i = u8 :: try_from ( i ) . unwrap ( ) ; } let ninfo = NeedleInfo { rarebytes : RareNeedleBytes :: new ( rare1i , rare2i ) , nhash : rabinkarp :: NeedleHash :: forward ( & needle ) , } ; Some ( PrefilterTest { ninfo , haystack , needle , output } ) }
Create a new prefilter test from a seed and some chose offsets to
rare bytes in the seed's needle.
Create a new prefilter test from a seed and some chose offsets to rare bytes in the seed ' s needle .
seed
&PrefilterTestSeed
rare1i
usize
rare2i
usize
haystack_len
usize
needle_len
usize
output
Option<usize>
seed
&PrefilterTestSeed
rare1i
usize
rare2i
usize
haystack_len
usize
needle_len
usize
output
Option<usize>