Line 20: |
Line 20: |
| end | | end |
| | | |
− | function p.hashString(string) | + | function p.hashString(str) |
| local hash = 0 | | local hash = 0 |
− | if string == nil or string == "" then | + | if str == nil or str == "" then |
| return 0 | | return 0 |
| end | | end |
− | for i = 1, #string do | + | if type(str) == "string" and str ~= "" then |
− | local letter = string:sub(i,i)
| + | for i = 1, #str do |
− | hash = bit32.lshift(hash,3)
| + | local letter = str:sub(i,i) |
− | hash = hash+string.byte(letter) % (2^31-1)
| + | hash = bit32.lshift(hash,3) |
| + | hash = hash+str.byte(letter) % (2^31-1) |
| + | end |
| end | | end |
| return hash | | return hash |