The Two Way algorithm is a substring search algorithm (primary paper, 1.4 MB PDF).
It splits the search pattern x in two parts: x = xl xr, and first it tries to match xr against the text, and if that is successful the algorithm prescribes matching xl in reverse (i.e. right-to-left order).
- Why is xl matched from right to left?
- Can I replace this with a left-to-right comparison instead?
The reason for the question is simple: An order unspecified comparison is already available and possibly more performant, think something like an optimized memcmp
or unrolled loop.