[Haskell-cafe] Text search

Ketil Malde ketil+haskell at ii.uib.no
Mon May 16 05:32:37 EDT 2005


Gracjan Polak <gracjan at acchsh.com> writes:

> find (isSuffixOf "needle") (inits "haystack")

Hmm...

While the result isn't exactly the same, I suspect 
using isPrefixOf and tails would be more efficient.

> This one is beautiful, but not very practical.

Unless you have very repetitive data and/or tiny alphabet, it is
actually quite efficient, as the expected length of prefixes that need
to be checked before a mismatch can be determined is small.

At least, I was unable to beat it with my (feeble attempts at) BM or
KMP implementations.

-kzm
-- 
If I haven't seen further, it is by standing in the footprints of giants



More information about the Haskell-Cafe mailing list