strstr sources: a summary of responses

Karl Heuer karl at haddock.ima.isc.com
Tue Aug 28 12:43:54 AEST 1990


In article <1158 at umvlsi.ecs.umass.edu> srivasta at umvlsi.ecs.umass.edu writes:
>[From the comments introducing John Lacey's Boyer-Moore code:]
>   Some rough timings found this implementation about twice as fast as 
>   the following straight string search.  ...
>   while ( text[i] && pattern[j] ) {
>       i++;
>       j = ( text[i] == pattern[j] ) ? j + 1 : 0;
>     }

I hope it's also more correct.  As written, this won't even handle
strstr("a", "a"); and even if you put the increment in a more likely place,
there's no provision for doing less than a full reset of the search--so
strstr("ababac", "abac") loses.

Karl W. Z. Heuer (karl at kelp.ima.isc.com or ima!kelp!karl), The Walking Lint



More information about the Comp.lang.c mailing list