-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fxhash to rustchash #8498
Fxhash to rustchash #8498
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I'll do the audit and merge this as well in another PR. Will link to it when it is ready.
Ah, looks like the Firefox folks kindly already audited |
|
||
/// A convenience functon for a quick usize hash | ||
#[inline] | ||
pub fn hash<T: std::hash::Hash + ?Sized>(v: &T) -> usize { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If your MSRV is at least 1.71, you might be interested in https://doc.rust-lang.org/std/hash/trait.BuildHasher.html#method.hash_one for this, though that gives u64
instead of usize
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the code I think that would work (and MSRV is 1.75)? Edit: doesn't seem possible due to FxHasher
not having the BuildHasher
trait
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
u64
would indeed be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To help avoid this problem in future I've gone and added an FxBuildHasher
to rustc-hash,
I'll try to remember to come back here and simplify #8677 once there's a new release of rustc-hash on crates-dot-io to use.
This removes the internal code for fxhash and instead uses the fxhash crate and subsequently migrates use of the fxhash crate (https://crates.io/crates/fxhash) to the rustc-hash crate (https://crates.io/crates/rustc-hash) implementing the same hash function: I believe the latter will need to be audited however: also manually implement the hash convenience function from fxhash --- @fitzgen