我是swift的新手。 我正在尝试编写以下代码来查找哈希值。但似乎这个代码正在泄露。
func CalculateHash(InputStr: String) -> UInt64 {
let PRIME = 12345678
var hash: UInt64 = 0
var iCnt: Int = 0
let Strlen = countElements(InputStr)
var UInt64EqOfChar: UInt64 = 0
// for (;iCnt < Strlen; ++iCnt) {
for TmpChar in InputStr {
//var CharName = InputStr[advance(InputStr.startIndex, iCnt)]
for TmpData in String(TmpChar).unicodeScalars {
UInt64EqOfChar = UInt64(TmpData.value)
}
hash += UInt64EqOfChar
// hash += (hash << 1)
hash ^= (hash >> 6)
}
hash += (hash << 12)
hash ^= (hash >> 23)
hash += (hash << 34)
hash = hash & UInt64(PRIME)
return hash
}