Python
Python copied to clipboard
Add FNV-1a hash algorithm implementation with 32-bit and 64-bit variants
Description
Add FNV-1a (Fowler-Noll-Vo) hash algorithm implementation to the hashes module.
Changes
- Add
hashes/fnv1a.pywith two functions:-
fnv1a_32(): 32-bit FNV-1a hash -
fnv1a_64(): 64-bit FNV-1a hash
-
Why this contribution?
- FNV-1a is a widely-used, fast, non-cryptographic hash function
- Missing from the current hash algorithms collection
- Educational value for understanding hash function design
- Better distribution properties than original FNV-1
Testing
- ✅ All 20 doctests pass
- ✅ Tested with various inputs (empty string, single char, long strings)
- ✅ Verified consistency (same input → same output)
- ✅ Verified differentiation (different inputs → different outputs)
- ✅ Type checking with mypy passes
- ✅ Code style checks with ruff pass
References
- Algorithm source: http://www.isthe.com/chongo/tech/comp/fnv/
- Wikipedia: https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function