FNV Hash Implementation

0.2.1 · active · verified Wed Apr 15

fnvhash is a pure Python implementation of the FNV (Fowler-Noll-Vo) hash function family, including FNV-1 and FNV-1a variants. It is known for its simplicity and speed in non-cryptographic hashing applications. The library is actively maintained, with its current version 0.2.1, and focuses on correctness with 100% test coverage.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import and use the 32-bit FNV-1a and 64-bit FNV-1 hash functions. It highlights the requirement for input data to be `bytes` objects.

from fnvhash import fnv1a_32, fnv1_64

data_str = "hello world"
data_bytes = data_str.encode('utf-8') # FNV hash functions expect bytes

# Calculate 32-bit FNV-1a hash
hash_32 = fnv1a_32(data_bytes)
print(f"FNV-1a 32-bit hash of '{data_str}': {hex(hash_32)}")

# Calculate 64-bit FNV-1 hash
long_data_str = "this is a slightly longer string for 64-bit hashing"
long_data_bytes = long_data_str.encode('utf-8')
hash_64 = fnv1_64(long_data_bytes)
print(f"FNV-1 64-bit hash of '{long_data_str}': {hex(hash_64)}")

view raw JSON →