用于实现Python str.count函数的算法 [英] Algorithm used to implement the Python str.count function

查看:148
本文介绍了用于实现Python str.count函数的算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读文档时遇到了Python str.count 函数。我似乎找不到关于该函数内部工作的任何很好的解释。什么算法用于计算字符串中子字符串的数量?

I came across the Python str.count function while reading the documentation. I can't seem to find any good explanation on the inner working of the function. What algorithm is used to count the number of substrings in a string? How does it actually work?

推荐答案

https://github.com/python/cpython/blob/master/Objects/stringlib/fastsearch.h

文件顶部的注释对此进行了说明:

A comment at the top of file explains this much:


快速搜索/计算实现的依据是,波依摩尔
和horspool之间的混合,顶部还有一些花哨的信息。有关
的更多背景信息,请参见: http://effbot.org/zone/stringlib.htm

这篇关于用于实现Python str.count函数的算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆