Python icon indicating copy to clipboard operation
Python copied to clipboard

Add FNV-1a hash algorithm implementation with 32-bit and 64-bit variants

Open dinilH opened this issue 2 months ago • 0 comments

Description

Add FNV-1a (Fowler-Noll-Vo) hash algorithm implementation to the hashes module.

Changes

  • Add hashes/fnv1a.py with 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

dinilH avatar Oct 30 '25 14:10 dinilH