http://stanford.edu/~jonr1/software-faire-poster.jpg (see center panel)
My thought process at the time was: Shit, brute force string search takes over ten minutes on my data! There must be a way to speed this up. Hm. It probably involves hashing somehow...
I wonder if the data in question was indexed, it'd have solved your problem in an instant?
Nah, it wasn't indexed, hence the necessity to build up such an index as the first step of the algorithm.
Depends on the scenario, of course, and judging by how you solved it, yours seems like an exception, and not rule.