-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Move FNV hashing from librustc to libstd #13300
Conversation
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
//! A speedy hash algorithm. Note that although this is far faster than SipHash, this is not |
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.
The statement that it's far faster than SipHash isn't really accurate. SipHash is faster than FNV, but has a large initial set up time so it doesn't break even without a long input. The SipHash implementation in Rust is also far from as fast as it could be.
I'm hesitant to add this to the standard library "just so we can have it", and I remember something similar to this was proposed recently, but I'm unable to find it now. The question that I would have is to what degree are we providing hashing algorithms? Why not provide things like sha1 and friends? Most of those probably don't belong in the standard library itself, but rather as part of the standard distribution. I would be more comfortable extracting this to |
I'd be very happy with an extraction to If you would rather me roll that into this PR, then I'm willing to do so, but I saw that as seperate and possibly worthy of a RFC. |
I've rebased, updated the benchmarks, added more documentation, and clarified when FNV hashing is useful. |
Closing due to inactivity, but feel free to reopen with a rebase! |
Okay, rebased. |
It looks like the rebasing has gone awry and picked up some extra commits? |
test hash::fnv::test::bench_compound_1 ... bench: 12 ns/iter (+/- 1) test hash::fnv::test::bench_long_str ... bench: 816 ns/iter (+/- 12) test hash::fnv::test::bench_str_of_8_bytes ... bench: 0 ns/iter (+/- 0) test hash::fnv::test::bench_str_over_8_bytes ... bench: 0 ns/iter (+/- 0) test hash::fnv::test::bench_str_under_8_bytes ... bench: 0 ns/iter (+/- 0) test hash::fnv::test::bench_u64 ... bench: 0 ns/iter (+/- 0) vs. test hash::sip::tests::bench_compound_1 ... bench: 66 ns/iter (+/- 35) test hash::sip::tests::bench_long_str ... bench: 747 ns/iter (+/- 904) test hash::sip::tests::bench_str_of_8_bytes ... bench: 38 ns/iter (+/- 54) test hash::sip::tests::bench_str_over_8_bytes ... bench: 44 ns/iter (+/- 26) test hash::sip::tests::bench_str_under_8_bytes ... bench: 36 ns/iter (+/- 13) test hash::sip::tests::bench_u64 ... bench: 30 ns/iter (+/- 14)
Whoops, sorry about that. I think it's fixed now. |
Why is siphash even in std if |
I agree with @alexcrichton that moving this hashing function into std is a step backwards (sideways maybe). |
Closing due to inactivity. I think that this may find a good home once |
Use cfg(any()) instead of cfg(FALSE) for disabling proc-macro test cc rust-lang/rust-analyzer#13286
check std::panic::panic_any in panic lint close rust-lang#13292 This PR detects `std::panic::panic_any` in panic lint. changelog: check std::panic::panic_any in panic lint
The FNV hashing code in rustc is generally applicable and very useful for anyone who doesn't need cryptographic strength. This should help with #11783.