博耶摩尔算法的实现?
有 C 语言的 Boyer-Moore 字符串搜索算法的工作示例吗? 我浏览了一些网站,但它们似乎有很多问题,包括维基百科。
谢谢。
Is there a working example of the Boyer-Moore string search algorithm in C?
I've looked at a few sites, but they seem pretty buggy, including wikipedia.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
子字符串搜索算法的最佳网站:
http://igm.univ-mlv.fr/~ lecroq/字符串/
The best site for substring search algorithms:
http://igm.univ-mlv.fr/~lecroq/string/
这是我用很多奇怪的测试用例强调的 C90 实现:
Here is a C90 implementation that I have stressed with a lot of strange test cases:
Bob Stout 的 Snippets 网站上有一些 Boyer-Moore-Horspool 的实现(包括周日的变体)。据我所知,Ray Gardner 在 BMHSRCH.C 中的实现没有错误知道1,绝对是我见过或听说过的最快的。然而,这并不是最容易理解的——他使用了一些相当棘手的代码来使内部循环尽可能简单。我可能有偏见,但我认为我的版本2位于 PBMSRCH.C 更容易理解一点(尽管肯定慢一点)。
1 在其限制范围内 - 它最初是为 MS-DOS 编写的,并且可以针对提供更多内存的环境进行重写。
2 这不知何故被标记为“Pratt-Boyer-Moore”,但实际上是 Boyer-Moore-Horspool 的周日变体(尽管我当时不知道并且没有发布它) ,我相信我实际上是在周日之前大约一年发明了它)。
There are a couple of implementations of Boyer-Moore-Horspool (including Sunday's variant) on Bob Stout's Snippets site. Ray Gardner's implementation in BMHSRCH.C is bug-free as far as I know1, and definitely the fastest I've ever seen or heard of. It's not, however, the easiest to understand -- he uses some fairly tricky code to keep the inner loop as a simple as possible. I may be biased, but I think my version2 in PBMSRCH.C is a bit easier to understand (though definitely a bit slower).
1 Within its limits -- it was originally written for MS-DOS, and could use a rewrite for environments that provide more memory.
2 This somehow got labeled as "Pratt-Boyer-Moore", but is actually Sunday's variant of Boyer-Moore-Horspool (though I wasn't aware of it at the time and didn't publish it, I believe I actually invented it about a year before Sunday did).