std::search 使用什么算法?
有很多字符串匹配算法可以用来在大文本中查找模式(字符串),例如 Boyer-Moore、Aho-Corasick 等。
使用哪种字符串匹配算法来实现 std::search
C++ 中的函数 ?
There are many string matching algorithms can be used to find a pattern (string) in a big text, like Boyer-Moore, Aho-Corasick, etc.
Which string matching algorithm is applied to implement std::search
function in C++ ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据 C++03 ISO 标准 §25.1.9/3,
std::search
的复杂度为这是该算法实现的唯一要求。 ISO 规范没有指定此处应使用哪种算法,它完全取决于实现。这些时间限制允许使用朴素的序列搜索算法,Knuth-Morris-普拉特,Boyer-Moore 和 Rabin-Karp。要了解正在使用哪一个,您可能应该获取您正在使用的标准库版本的文档。也就是说,你不能指望它是便携式的。我的猜测是,大多数实现只使用朴素的匹配算法,因为最坏的情况在实践中通常不会出现。
希望这有帮助!
According to the C++03 ISO standard, §25.1.9/3, the complexity of
std::search
isThis is the only requirement on the implementation of this algorithm. The ISO spec does not specify which algorithm should be used here, and it's completely implementation-dependent. These time bounds permit the use of the naive sequence-searching algorithm, Knuth-Morris-Pratt, Boyer-Moore, and Rabin-Karp. To know which one is being used, you should probably pull up the documentation for whichever version of the standard library that you're using. That said, you can't count on that being portable. My guess is that most implementations just use the naive matching algorithm, since the worst case typically doesn't arise in practice.
Hope this helps!