How is string.find implemented in CPython?

后端 未结 3 1796
囚心锁ツ
囚心锁ツ 2020-12-19 03:52

I was wondering if the \'find\' method on strings was implemented with a linear search, or if python did something more sophisticated. The Python documentation doesn\'t disc

相关标签:
3条回答
  • 2020-12-19 04:15

    Looks like the algorithm used originates from Boyer-Moore-Horspool algorithm

    0 讨论(0)
  • 2020-12-19 04:26

    You should be able to find it in Objects/stringlib/find.h, although the real code is in fastsearch.h.

    0 讨论(0)
  • 2020-12-19 04:28

    The comment on the implementation has the following to say:

    fast search/count implementation, based on a mix between boyer-moore and horspool, with a few more bells and whistles on the top.

    for some more background, see: http://effbot.org/zone/stringlib.htm

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

    0 讨论(0)
提交回复
热议问题