Skip to content

Conversation

@rodrigobnogueira
Copy link

@rodrigobnogueira rodrigobnogueira commented Dec 25, 2025

Description

Implements the FNV-1a (Fowler-Noll-Vo) hash algorithm with both 32-bit and 64-bit variants. FNV-1a is a fast, non-cryptographic hash function widely used in hash tables, bloom filters, and caches.

Changes

  • Added hashes/fnv.py with complete implementation of:
    • fnv1a_32(): 32-bit variant
    • fnv1a_64(): 64-bit variant
  • Simple XOR-multiply algorithm
  • 22 comprehensive doctests (11 per variant)
  • Full type hints and English documentation

Features

  • Extremely simple and fast implementation
  • Excellent distribution properties
  • Used in popular systems (hash tables, databases)
  • Complements existing hash algorithms (CRC32, MD5, SHA)

Real-world Applications

  • Hash tables and hash maps
  • Bloom filters
  • Database indexing
  • Cache implementations
  • Checksums for data integrity

References

Testing

  • All 22 doctests pass
  • Passes ruff linting
  • Passes mypy type checking
  • Tested with various inputs including edge cases

Checklist

  • I have read and followed the contributing guidelines
  • This pull request is not a duplicate
  • The algorithm is implemented from scratch
  • The code follows the repository style
  • I have read CONTRIBUTING.md
  • This pull request is all my own work -- I have not plagiarized
  • I know that pull requests will not be merged if they fail the automated tests
  • This PR only changes one algorithm file
  • All new Python files are placed inside an existing directory (hashes/)
  • All filenames are in all lowercase characters with no spaces or dashes
  • All functions and variable names follow Python naming conventions
  • All function parameters and return values are annotated with Python type hints
  • All functions have doctests that pass the automated testing
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation

- Implement FNV-1a with 32-bit and 64-bit variants
- Add 22 comprehensive doctests (11 per variant)
- Full type hints and English documentation
- Passes ruff and mypy checks

FNV-1a is widely used in hash tables, bloom filters, and caches.
Simple XOR-multiply algorithm with excellent distribution properties.
@algorithms-keeper algorithms-keeper bot added the awaiting reviews This PR is ready to be reviewed label Dec 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant