Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

gereeter
Copy link
Contributor

@gereeter gereeter commented Apr 4, 2014

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.

// 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
Copy link
Contributor

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.

@alexcrichton
Copy link
Member

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 libhash, but even that is not necessarily the best solution.

@gereeter
Copy link
Contributor Author

I'd be very happy with an extraction to libhash, but I viewed that as an orthogonal change. The proposal you were mentioning came from #11783 by @erickt. Based on the discussion there, I assumed that this would either go in std::hash or libhash, but, given that libhash does not even exist yet, the discussion of which is correct and how many algorithms we provide would go in the PR creating libhash.

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.

@gereeter
Copy link
Contributor Author

I've rebased, updated the benchmarks, added more documentation, and clarified when FNV hashing is useful.

@alexcrichton
Copy link
Member

Closing due to inactivity, but feel free to reopen with a rebase!

@gereeter
Copy link
Contributor Author

gereeter commented May 4, 2014

Okay, rebased.

@alexcrichton alexcrichton reopened this May 4, 2014
@alexcrichton
Copy link
Member

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)
@gereeter
Copy link
Contributor Author

gereeter commented May 4, 2014

Whoops, sorry about that. I think it's fixed now.

@brson
Copy link
Contributor

brson commented May 19, 2014

Why is siphash even in std if HashMap has moved to libcollections?

@brson
Copy link
Contributor

brson commented May 19, 2014

I agree with @alexcrichton that moving this hashing function into std is a step backwards (sideways maybe).

@alexcrichton
Copy link
Member

Closing due to inactivity. I think that this may find a good home once hash lives in libcollections (see #14538), but it may want to wait for that to land.

@gereeter gereeter deleted the fnv-in-std branch December 17, 2015 01:29
matthiaskrgr pushed a commit to matthiaskrgr/rust that referenced this pull request Oct 11, 2022
Use cfg(any()) instead of cfg(FALSE) for disabling proc-macro test

cc rust-lang/rust-analyzer#13286
flip1995 pushed a commit to flip1995/rust that referenced this pull request Sep 5, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants