phabet _ index ( T [ h ]) ][ i ] ▁▁▁▁▁▁▁▁▁▁▁▁ ▁if ▁i + 1 ▁== ▁len ( P ): ▁▁ ▁# ▁M ism atch ▁happened ▁on ▁first ▁attempt ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▁suffix _ shift ▁= ▁ 1 ▁▁▁▁▁▁▁▁▁▁▁▁ ▁elif ▁L [ i + 1 ] ▁== ▁- 1 : ▁▁ ▁# ▁Match ed ▁suffix ▁does ▁not ▁appear ▁anywhere ▁in ▁P ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▁suffix _ shift ▁= ▁len ( P ) ▁- ▁F [ i + 1 ] ▁▁▁▁▁▁▁▁▁▁▁▁ ▁else : ▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▁# ▁Match ed ▁suffix ▁appears ▁in ▁P ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▁suffix _ shift ▁= ▁len ( P ) ▁- ▁ 1 ▁- ▁L [ i + 1 ] ▁▁▁▁▁▁▁▁▁▁▁▁ ▁shift ▁= ▁max ( char _ shift , ▁suffix _ shift ) ▁▁▁▁▁▁▁▁▁▁▁▁ ▁previous _ k ▁= ▁k ▁if ▁shift ▁>= ▁i + 1 ▁else ▁previous _ k ▁ ▁# ▁Gal il ' s ▁rule ▁▁▁▁▁▁▁▁▁▁▁▁ ▁k ▁+= ▁shift ▁▁▁▁ ▁return ▁matches ▁ ▁[ C ▁implementation ] ▁# include ▁< std int . h > ▁# include ▁< std def . h > ▁# include ▁< std bool . h > ▁# include ▁< std lib . h > ▁ ▁# define ▁A LP H AB ET _ LE N ▁ 2 5 6 ▁# define ▁max ( a , ▁b ) ▁(( a ▁< ▁b ) ▁? ▁b ▁: ▁a ) ▁ ▁// ▁B AD ▁CHAR ACT ER ▁R U LE . ▁// ▁delta 1 ▁table : ▁delta 1 [ c ] ▁contains ▁the ▁distance ▁between ▁the ▁last ▁// ▁character ▁of ▁pat ▁and ▁the ▁right