pub fn new<'b>(needle: &'b [u8]) -> TwoWaySearcher<'b> {
        if needle.is_empty() {
            return TwoWaySearcher {
                needle: needle,
                crit_pos: 0,
                period: 0,
                byteset: 0,
                is_long: false,
            };
        }

        let (crit_pos_false, period_false) = TwoWaySearcher::maximal_suffix(needle, false);
        let (crit_pos_true, period_true) = TwoWaySearcher::maximal_suffix(needle, true);

        let (crit_pos, period) =
            if crit_pos_false > crit_pos_true {
                (crit_pos_false, period_false)
            } else {
                (crit_pos_true, period_true)
            };

        // A particularly readable explanation of what's going on here can be found
        // in Crochemore and Rytter's book "Text Algorithms", ch 13. Specifically
        // see the code for "Algorithm CP" on p. 323.
        //
        // What's going on is we have some critical factorization (u, v) of the
        // needle, and we want to determine whether u is a suffix of
        // &v[..period]. If it is, we use "Algorithm CP1". Otherwise we use
        // "Algorithm CP2", which is optimized for when the period of the needle
        // is large.
        if &needle[..crit_pos] == &needle[period.. period + crit_pos] {
            // short period case -- the period is exact
            // compute a separate critical factorization for the reversed needle
            // x = u' v' where |v'| < period(x).
            //
            // This is sped up by the period being known already.

            TwoWaySearcher {
                needle: needle,
                crit_pos: crit_pos,
                period: period,
                byteset: Self::byteset_create(&needle[..period]),
                is_long: false,
            }
        } else {
            // long period case -- we have an approximation to the actual period,
            // and don't use memorization.
            //
            // Approximate the period by lower bound max(|u|, |v|) + 1.

            TwoWaySearcher {
                needle: needle,
                crit_pos: crit_pos,
                period: cmp::max(crit_pos, needle.len() - crit_pos) + 1,
                byteset: Self::byteset_create(needle),
                is_long: true,
            }
        }
    }
/// Creates a new `TwoWaySearcher` that can be used to search for `needle`.
Creates a new `TwoWaySearcher` that can be used to search for `needle`.
Creates a new ` TwoWaySearcher ` that can be used to search for ` needle ` .
pub fn new<'b>(needle: &'b [u8]) -> TwoWaySearcher<'b> {
        if needle.is_empty() {
            return TwoWaySearcher {
                needle: needle,
                crit_pos: 0,
                period: 0,
                byteset: 0,
                is_long: false,
            };
        }
        let (crit_pos_false, period_false) = TwoWaySearcher::maximal_suffix(needle, false);
        let (crit_pos_true, period_true) = TwoWaySearcher::maximal_suffix(needle, true);
        let (crit_pos, period) =
            if crit_pos_false > crit_pos_true {
                (crit_pos_false, period_false)
            } else {
                (crit_pos_true, period_true)
            };
        // A particularly readable explanation of what's going on here can be found
        // in Crochemore and Rytter's book "Text Algorithms", ch 13. Specifically
        // see the code for "Algorithm CP" on p. 323.
        //
        // What's going on is we have some critical factorization (u, v) of the
        // needle, and we want to determine whether u is a suffix of
        // &v[..period]. If it is, we use "Algorithm CP1". Otherwise we use
        // "Algorithm CP2", which is optimized for when the period of the needle
        // is large.
        if &needle[..crit_pos] == &needle[period.. period + crit_pos] {
            // short period case -- the period is exact
            // compute a separate critical factorization for the reversed needle
            // x = u' v' where |v'| < period(x).
            //
            // This is sped up by the period being known already.
            TwoWaySearcher {
                needle: needle,
                crit_pos: crit_pos,
                period: period,
                byteset: Self::byteset_create(&needle[..period]),
                is_long: false,
            }
        } else {
            // long period case -- we have an approximation to the actual period,
            // and don't use memorization.
            //
            // Approximate the period by lower bound max(|u|, |v|) + 1.
            TwoWaySearcher {
                needle: needle,
                crit_pos: crit_pos,
                period: cmp::max(crit_pos, needle.len() - crit_pos) + 1,
                byteset: Self::byteset_create(needle),
                is_long: true,
            }
        }
    }
pub fn new < ' b > ( needle : & ' b [ u8 ] ) -> TwoWaySearcher < ' b > { if needle . is_empty ( ) { return TwoWaySearcher { needle : needle , crit_pos : 0 , period : 0 , byteset : 0 , is_long : false , } ; } let ( crit_pos_false , period_false ) = TwoWaySearcher :: maximal_suffix ( needle , false ) ; let ( crit_pos_true , period_true ) = TwoWaySearcher :: maximal_suffix ( needle , true ) ; let ( crit_pos , period ) = if crit_pos_false > crit_pos_true { ( crit_pos_false , period_false ) } else { ( crit_pos_true , period_true ) } ; // A particularly readable explanation of what's going on here can be found // in Crochemore and Rytter's book "Text Algorithms", ch 13. Specifically // see the code for "Algorithm CP" on p. 323. // // What's going on is we have some critical factorization (u, v) of the // needle, and we want to determine whether u is a suffix of // &v[..period]. If it is, we use "Algorithm CP1". Otherwise we use // "Algorithm CP2", which is optimized for when the period of the needle // is large. if & needle [ .. crit_pos ] == & needle [ period .. period + crit_pos ] { // short period case -- the period is exact // compute a separate critical factorization for the reversed needle // x = u' v' where |v'| < period(x). // // This is sped up by the period being known already. TwoWaySearcher { needle : needle , crit_pos : crit_pos , period : period , byteset : Self :: byteset_create ( & needle [ .. period ] ) , is_long : false , } } else { // long period case -- we have an approximation to the actual period, // and don't use memorization. // // Approximate the period by lower bound max(|u|, |v|) + 1. TwoWaySearcher { needle : needle , crit_pos : crit_pos , period : cmp :: max ( crit_pos , needle . len ( ) - crit_pos ) + 1 , byteset : Self :: byteset_create ( needle ) , is_long : true , } } }
Creates a new `TwoWaySearcher` that can be used to search for `needle`.
Creates a new ` TwoWaySearcher ` that can be used to search for ` needle ` .
needle
&'b [u8]
needle
&'b [u8]