tkaitchuck / aHash

aHash is a non-cryptographic hashing algorithm that uses the AES hardware instruction
https://crates.io/crates/ahash
Apache License 2.0
1.03k stars 101 forks source link

Hashing `&T` yields different results compared to `T` #214

Closed nameexhaustion closed 7 months ago

nameexhaustion commented 7 months ago
fn test() {
    use std::hash::BuildHasher;

    let x = 10;

    println!("x: {}", x);

    let rs = ahash::RandomState::new();

    println!("ahash hash_one(x)  {}", rs.clone().hash_one(x));
    println!("ahash hash_one(&x) {}", rs.clone().hash_one(&x));

    let rs = std::hash::RandomState::new();

    println!("std hash_one(x)    {}", rs.clone().hash_one(x));
    println!("std hash_one(&x)   {}", rs.clone().hash_one(&x));
}
x: 10
ahash hash_one(x)  3042556146200844667
ahash hash_one(&x) 14656816703936529722
std hash_one(x)    3528508081386770256
std hash_one(&x)   3528508081386770256

I believe this is not desirable behavior, I would instead expect hash(x) <=> hash(&x). This appears to be due to missing an impl for hash specialization on &T where T is a type that has specialized hash impls.