-
Notifications
You must be signed in to change notification settings - Fork 53
incorrect hash impl #72
Copy link
Copy link
Closed
Description
https://doc.rust-lang.org/std/hash/trait.Hash.html#hash-and-eq
When implementing both Hash and Eq, it is important that the following property holds:
k1 == k2 -> hash(k1) == hash(k2)
In other words, if two keys are equal, their hashes must also be equal
UniCase<S: AsRef<str>> implements Hash + Eq, so the above requirement must be satisfied. The following test case fails:
use std::hash::BuildHasher;
use foldhash::quality::RandomState;
use unicase::UniCase;
let k1 = UniCase::unicode("Foo");
let k2 = UniCase::new("foO");
assert_eq!(k1, k2);
let h = RandomState::default();
assert_eq!(h.hash_one(k1), h.hash_one(k2));This occurs because UniCase::unicode produces b"f", b"o", b"o", while UniCase::new (with ascii) produces b'f', b'o', b'o', which is not guaranteed to be the same under Hasher.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels