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 4cf229d commit 42139fdCopy full SHA for 42139fd
1 file changed
hashes/joaat.py
@@ -6,9 +6,19 @@
6
"""
7
8
def joaat(key: str) -> int:
9
+ """
10
+ Calculate Jenkins One-at-a-Time hash for a key.
11
+
12
+ >>> joaat("apple")
13
+ 2297466611
14
+ >>> joaat("test")
15
+ 1064684737
16
+ >>> joaat("")
17
+ 0
18
19
hash = 0
20
mask = 0xFFFFFFFF
- key_bytes = key.encode('utf-8')
21
+ key_bytes = key.encode("utf-8")
22
23
for byte in key_bytes:
24
hash = (hash + byte) & mask
@@ -20,3 +30,7 @@ def joaat(key: str) -> int:
30
hash = (hash + (hash << 15)) & mask
31
32
return hash
33
34
+if __name__ == "__main__":
35
+ import doctest
36
+ doctest.testmod()
0 commit comments