pub struct PolymurHash { /* private fields */ }Expand description
A fast, non-cryptographic hash function based on polynomial evaluation.
PolymurHash is a universal hash function that provides excellent performance and good distribution properties. It’s particularly well-suited for hash tables and other non-cryptographic applications.
§Examples
Basic usage:
use polymur_hash::PolymurHash;
let hasher = PolymurHash::new(0);
let data = b"Hello, world!";
let hash = hasher.hash(data);Using with a custom seed:
use polymur_hash::PolymurHash;
let seed = 0xDEADBEEFCAFEBABE_u64;
let hasher = PolymurHash::from_u64_seed(seed);
let hash = hasher.hash(b"Some data");Hash with tweak for additional randomization:
use polymur_hash::PolymurHash;
let hasher = PolymurHash::new(42);
let tweak = 0x123456789ABCDEF0;
let hash = hasher.hash_with_tweak(b"Data", tweak);Implementations§
Source§impl PolymurHash
impl PolymurHash
Sourcepub fn from_u64_seed(seed: u64) -> Self
pub fn from_u64_seed(seed: u64) -> Self
Sourcepub fn from_u64x2_seed(k_seed: u64, s_seed: u64) -> Self
pub fn from_u64x2_seed(k_seed: u64, s_seed: u64) -> Self
Creates a new PolymurHash instance from two 64-bit seeds.
This provides direct control over the key and state seeds.
§Arguments
k_seed- Seed for the polynomial key generations_seed- Seed for the final mixing state
§Examples
use polymur_hash::PolymurHash;
let hasher = PolymurHash::from_u64x2_seed(0x12345678, 0x9ABCDEF0);Sourcepub fn hash_with_tweak(&self, buf: impl AsRef<[u8]>, tweak: u64) -> u64
pub fn hash_with_tweak(&self, buf: impl AsRef<[u8]>, tweak: u64) -> u64
Computes the hash of the given data with an additional tweak value.
The tweak allows for additional randomization without changing the key. This is useful for applications that need multiple independent hash values from the same key.
§Arguments
buf- The data to hashtweak- An additional value to mix into the hash
§Examples
use polymur_hash::PolymurHash;
let hasher = PolymurHash::new(0);
let data = b"Hello, world!";
let hash1 = hasher.hash_with_tweak(data, 1);
let hash2 = hasher.hash_with_tweak(data, 2);
assert_ne!(hash1, hash2); // Different tweaks produce different hashesTrait Implementations§
Source§impl Clone for PolymurHash
impl Clone for PolymurHash
Source§fn clone(&self) -> PolymurHash
fn clone(&self) -> PolymurHash
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for PolymurHash
impl RefUnwindSafe for PolymurHash
impl Send for PolymurHash
impl Sync for PolymurHash
impl Unpin for PolymurHash
impl UnwindSafe for PolymurHash
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more