Code
Hub
Workspaces
Following
Trending
Connect
MCP
copy
Create free account
hub
/
github.com/Jack-Lee-Hiter/AlgorithmsByPython
/ hash2
Function
hash2
Hash.py:16–20 ·
view source on GitHub ↗
(astring, tablesize)
Source
from the content-addressed store, hash-verified
14
15
# 改进hash, 让每一位的字母乘以该字母在字串中的位置然后mod
16
def
hash2(astring, tablesize):
17
sum = 0
18
for
pos in range(len(astring)):
19
sum += (pos+1) * ord(astring[pos])
20
return
sum%tablesize
21
22
print(hash2(
'cat'
, 11))
23
Callers
1
Hash.py
File · 0.85
Calls
no outgoing calls
Tested by
no test coverage detected