[Home]
[Contents]
[Chapter]
[Previous Algorithm]
[Next Algorithm]


Boyer-Moore text searching


char *search( pat, text, n ) char *pat, *text; int n; { int j, k, m, skip[MAXCHAR], d[MAXPATLEN]; m = strlen(pat); if( m == 0 ) return( text ); preprocpat( pat, skip, d ); for( k=m-1; k<n; k += max(skip[text[k] &(MAXCHAR-1)],d[j])) { for( j=m-1; j >= 0 && text[k] == pat[j]; j-- ) k--; if( j ==(-1) ) return( text+k+1 ); } return( NULL ); }

C source (713a.srch.c)



© Addison-Wesley Publishing Co. Inc.