MCPcopy
hub / github.com/itcharge/AlgoNote / generateBadCharTable

Function generateBadCharTable

codes/python/04_string/string_horspool.py:19–25  ·  view source on GitHub ↗
(p: str)

Source from the content-addressed store, hash-verified

17# 生成后移位数表
18# bc_table[bad_char] 表示遇到坏字符可以向右移动的距离
19def generateBadCharTable(p: str):
20 m = len(p)
21 bc_table = dict()
22
23 for i in range(m - 1): # 迭代到 m - 2
24 bc_table[p[i]] = m - 1 - i # 更新遇到坏字符可向右移动的距离
25 return bc_table
26
27print(horspool("abbcfdddbddcaddebc", "aaaaa"))
28print(horspool("abbcfdddbddcaddebc", "bcf"))

Callers 1

horspoolFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected