Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add joaat function for non-cryptographic hashing
Implement the Jenkins-One-At-A-Time hash function.
  • Loading branch information
Sarbatore authored Apr 14, 2026
commit 4cf229d9f0fd302d5c748421c2c2f3ceafbc0648
22 changes: 22 additions & 0 deletions hashes/joaat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
The Bob Jenkins hash is a fast, non-cryptographic hash function
designed for general-purpose use, such as hash table lookups.

source: https://en.wikipedia.org/wiki/Jenkins_hash_function
"""

def joaat(key: str) -> int:
hash = 0
mask = 0xFFFFFFFF
key_bytes = key.encode('utf-8')

for byte in key_bytes:
hash = (hash + byte) & mask
hash = (hash + (hash << 10)) & mask
hash = (hash ^ (hash >> 6)) & mask

hash = (hash + (hash << 3)) & mask
hash = (hash ^ (hash >> 11)) & mask
hash = (hash + (hash << 15)) & mask

return hash