[Haskell-cafe] Text search
bulatz at HotPOP.com
Mon May 16 10:29:09 EDT 2005
Monday, May 16, 2005, 4:00:33 PM, you wrote:
GP> > Unless you have very repetitive data and/or tiny alphabet, it is
GP> > actually quite efficient, as the expected length of prefixes that need
GP> > to be checked before a mismatch can be determined is small.
GP> > At least, I was unable to beat it with my (feeble attempts at) BM or
GP> > KMP implementations.
if you really need KMP, you can find it at http://haskell.org/hawiki/RunTimeCompilation
> find (isSuffixOf "needle") (inits "haystack")
find (isPrefixOf "needle") (tails "haystack")
if you need an index - add it with zip:
find (isPrefixOf "needle".snd) (zip [0..] (tails "haystack"))
Bulat mailto:bulatz at HotPOP.com
More information about the Haskell-Cafe