pub fn new<C, P>(pattern: P) -> Self
    where
        C: Borrow<u8> + Ord,
        P: IntoIterator<Item = C>,
        P::IntoIter: DoubleEndedIterator + ExactSizeIterator + Clone,
    {
        let pattern = pattern.into_iter();
        let m = pattern.len();
        let maxsym = *pattern
            .clone()
            .max()
            .expect("Expecting non-empty pattern.")
            .borrow() as usize;
        let mut table: Vec<VecMap<usize>> = Vec::with_capacity(m);
        // init suffix table, initially all values unknown
        // suff[i] is the state in which the longest suffix of
        // pattern[..i+1] ends that does not end in i
        let mut suff: Vec<Option<usize>> = repeat(None).take(m + 1).collect();

        for (j, b) in pattern.rev().enumerate() {
            let i = j + 1;
            let a = *b.borrow() as usize;
            let mut delta = VecMap::with_capacity(maxsym);
            // reading symbol a leads into state i (this is an inner edge)
            delta.insert(a, i);
            // now, add edges for substrings ending with a
            let mut k = suff[i - 1];

            // for this iterate over the known suffixes until
            // reaching an edge labelled with a or the start
            while let Some(k_) = k {
                if table[k_].contains_key(a) {
                    break;
                }
                table[k_].insert(a, i);
                k = suff[k_];
            }

            // the longest suffix is either 0 or the state
            // reached by the edge labelled with a
            suff[i] = Some(match k {
                Some(k) => *table[k].get(a).unwrap(),
                None => 0,
            });

            table.push(delta);
        }

        BOM { m, table }
    }
/// Create a new instance for a given pattern.
Create a new instance for a given pattern.
Create a new instance for a given pattern .
pub fn new<C, P>(pattern: P) -> Self
    where
        C: Borrow<u8> + Ord,
        P: IntoIterator<Item = C>,
        P::IntoIter: DoubleEndedIterator + ExactSizeIterator + Clone,
    {
        let pattern = pattern.into_iter();
        let m = pattern.len();
        let maxsym = *pattern
            .clone()
            .max()
            .expect("Expecting non-empty pattern.")
            .borrow() as usize;
        let mut table: Vec<VecMap<usize>> = Vec::with_capacity(m);
        // init suffix table, initially all values unknown
        // suff[i] is the state in which the longest suffix of
        // pattern[..i+1] ends that does not end in i
        let mut suff: Vec<Option<usize>> = repeat(None).take(m + 1).collect();
        for (j, b) in pattern.rev().enumerate() {
            let i = j + 1;
            let a = *b.borrow() as usize;
            let mut delta = VecMap::with_capacity(maxsym);
            // reading symbol a leads into state i (this is an inner edge)
            delta.insert(a, i);
            // now, add edges for substrings ending with a
            let mut k = suff[i - 1];
            // for this iterate over the known suffixes until
            // reaching an edge labelled with a or the start
            while let Some(k_) = k {
                if table[k_].contains_key(a) {
                    break;
                }
                table[k_].insert(a, i);
                k = suff[k_];
            }
            // the longest suffix is either 0 or the state
            // reached by the edge labelled with a
            suff[i] = Some(match k {
                Some(k) => *table[k].get(a).unwrap(),
                None => 0,
            });
            table.push(delta);
        }
        BOM { m, table }
    }
pub fn new < C , P > ( pattern : P ) -> Self where C : Borrow < u8 > + Ord , P : IntoIterator < Item = C > , P :: IntoIter : DoubleEndedIterator + ExactSizeIterator + Clone , { let pattern = pattern . into_iter ( ) ; let m = pattern . len ( ) ; let maxsym = * pattern . clone ( ) . max ( ) . expect ( " " ) . borrow ( ) as usize ; let mut table : Vec < VecMap < usize > > = Vec :: with_capacity ( m ) ; // init suffix table, initially all values unknown // suff[i] is the state in which the longest suffix of // pattern[..i+1] ends that does not end in i let mut suff : Vec < Option < usize > > = repeat ( None ) . take ( m + 1 ) . collect ( ) ; for ( j , b ) in pattern . rev ( ) . enumerate ( ) { let i = j + 1 ; let a = * b . borrow ( ) as usize ; let mut delta = VecMap :: with_capacity ( maxsym ) ; // reading symbol a leads into state i (this is an inner edge) delta . insert ( a , i ) ; // now, add edges for substrings ending with a let mut k = suff [ i - 1 ] ; // for this iterate over the known suffixes until // reaching an edge labelled with a or the start while let Some ( k_ ) = k { if table [ k_ ] . contains_key ( a ) { break ; } table [ k_ ] . insert ( a , i ) ; k = suff [ k_ ] ; } // the longest suffix is either 0 or the state // reached by the edge labelled with a suff [ i ] = Some ( match k { Some ( k ) => * table [ k ] . get ( a ) . unwrap ( ) , None => 0 , } ) ; table . push ( delta ) ; } BOM { m , table } }
Create a new instance for a given pattern.
Create a new instance for a given pattern .
pattern
P
pattern
P