Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bbbd121

Browse files
author
ggl
committed
完善RK匹配算法注释
1 parent 4b9b492 commit bbbd121

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

String/BFRKSearch.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ func rkSearch(subString: String, mainString: String) -> Int? {
8686
// 字符a的ascii值
8787
let aAsciiValue = Character("a").asciiValue!
8888

89-
// 使用快捷计算公式:h[i] = (h[i-1] - 26^(m-1) * (S[i-1] - 'a')) * 26 + (s[i+m-1] - 'a')
89+
// 使用快捷计算公式:h[i] = (h[i-1] - 26^(m-1) * (S[i-1] - 'a')) * 26 + (s[i+m-1] - 'a'),
90+
// 其中m代表子串长度,i代表子串在主串中的起始位置;
9091
// 其中h[i]对应子串S[i-1...i+m-2]的哈希值,h[i]代表对应子串S[i...i+m-1]的哈希值,m代表子串的长度
9192
let preChHashValue = Int(mainString[mainString.index(before: curIndex)].asciiValue! - aAsciiValue + 1)
9293
let endChHashValue = Int(mainString[endIndex].asciiValue! - aAsciiValue + 1)

0 commit comments

Comments
 (0)