We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 566fa0e commit 6a57de7Copy full SHA for 6a57de7
hashes/polynomial_hash.py
@@ -9,14 +9,17 @@
9
Returns: int: The computed hash value.
10
Wikipedia :: https://en.wikipedia.org/wiki/Hash_function
11
"""
12
+
13
14
def polynomial_hash(s, p=31, m=10**9 + 9):
15
hash_value = 0
16
p_pow = 1
17
for char in s:
- char_value = ord(char) - ord('a') + 1 # Convert character to a numerical value
18
+ char_value = ord(char) - ord("a") + 1 # Convert character to a numerical value
19
hash_value = (hash_value + char_value * p_pow) % m
20
p_pow = (p_pow * p) % m
21
return hash_value
22
-print(polynomial_hash('PythonLanguage'))
23
24
+print(polynomial_hash("PythonLanguage"))
25
# Output: 877483825
0 commit comments