| Crates.io | polymur-hash |
| lib.rs | polymur-hash |
| version | 0.2.2 |
| created_at | 2023-10-18 18:02:55.185339+00 |
| updated_at | 2025-06-04 08:13:02.095233+00 |
| description | Polymur hash function |
| homepage | https://github.com/jedisct1/rust-polymur-hash |
| repository | https://github.com/jedisct1/rust-polymur-hash |
| max_upload_size | |
| id | 1007027 |
| size | 49,464 |
A fast, non-cryptographic hash function for Rust. This is a Rust port of the PolymurHash universal hash function.
no_std Compatible: Can be used in embedded and kernel contextsAdd this to your Cargo.toml:
[dependencies]
polymur-hash = "0.2"
use polymur_hash::PolymurHash;
// Create a hasher with a default seed
let hasher = PolymurHash::new(0);
// Hash some data
let data = b"Hello, world!";
let hash = hasher.hash(data);
println!("Hash: {:x}", hash);
use polymur_hash::PolymurHash;
// From a 64-bit seed
let hasher = PolymurHash::from_u64_seed(0xDEADBEEF);
// From a 128-bit seed
let hasher = PolymurHash::new(0x123456789ABCDEF0u128 << 64 | 0xFEDCBA9876543210u128);
// From two 64-bit seeds (key and state)
let hasher = PolymurHash::from_u64x2_seed(0x12345678, 0x9ABCDEF0);
Tweaks allow you to generate different hash values from the same key without reinitializing:
use polymur_hash::PolymurHash;
let hasher = PolymurHash::new(42);
let data = b"Some data";
// Generate multiple independent hashes
let hash1 = hasher.hash_with_tweak(data, 0);
let hash2 = hasher.hash_with_tweak(data, 1);
let hash3 = hasher.hash_with_tweak(data, 2);
// All hashes will be different
assert_ne!(hash1, hash2);
assert_ne!(hash2, hash3);
PolymurHash is designed for high performance. On modern processors, it achieves speeds comparable to other fast non-cryptographic hash functions like XXH3.
To run the benchmarks:
cargo bench
PolymurHash is based on polynomial evaluation in the finite field GF(2^61-1). It uses:
This implementation:
unsafe code#![forbid(unsafe_code)] enforcedThis project is licensed under the MIT License - see the LICENSE file for details.