-
Notifications
You must be signed in to change notification settings - Fork 319
Change DefaultHashBuilder to an opaque newtype
#643
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
Merged
+89
−10
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| [package] | ||
| name = "hashbrown" | ||
| version = "0.15.5" | ||
| version = "0.16.0" | ||
| authors = ["Amanieu d'Antras <[email protected]>"] | ||
| description = "A Rust port of Google's SwissTable hash map" | ||
| license = "MIT OR Apache-2.0" | ||
|
|
@@ -30,6 +30,7 @@ allocator-api2 = { version = "0.2.9", optional = true, default-features = false, | |
| ] } | ||
|
|
||
| # Equivalent trait which can be shared with other hash table implementations. | ||
| # NB: this is a public dependency because `Equivalent` is re-exported! | ||
| equivalent = { version = "1.0", optional = true, default-features = false } | ||
|
|
||
| [dev-dependencies] | ||
|
|
@@ -46,7 +47,7 @@ default = ["default-hasher", "inline-more", "allocator-api2", "equivalent", "raw | |
|
|
||
| # Enables use of nightly features. This is only guaranteed to work on the latest | ||
| # version of nightly Rust. | ||
| nightly = ["bumpalo/allocator_api"] | ||
| nightly = ["foldhash?/nightly", "bumpalo/allocator_api"] | ||
|
|
||
| # Enables the RustcEntry API used to provide the standard library's Entry API. | ||
| rustc-internal-api = [] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| #[cfg(feature = "default-hasher")] | ||
| use { | ||
| core::hash::{BuildHasher, Hasher}, | ||
| foldhash::fast::RandomState, | ||
| }; | ||
|
|
||
| /// Default hash builder for the `S` type parameter of | ||
| /// [`HashMap`](crate::HashMap) and [`HashSet`](crate::HashSet). | ||
| /// | ||
| /// This only implements `BuildHasher` when the "default-hasher" crate feature | ||
| /// is enabled; otherwise it just serves as a placeholder, and a custom `S` type | ||
| /// must be used to have a fully functional `HashMap` or `HashSet`. | ||
| #[derive(Clone, Debug, Default)] | ||
| pub struct DefaultHashBuilder { | ||
| #[cfg(feature = "default-hasher")] | ||
| inner: RandomState, | ||
| } | ||
|
|
||
| #[cfg(feature = "default-hasher")] | ||
| impl BuildHasher for DefaultHashBuilder { | ||
| type Hasher = DefaultHasher; | ||
|
|
||
| #[inline(always)] | ||
| fn build_hasher(&self) -> Self::Hasher { | ||
| DefaultHasher { | ||
| inner: self.inner.build_hasher(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Default hasher for [`HashMap`](crate::HashMap) and [`HashSet`](crate::HashSet). | ||
| #[cfg(feature = "default-hasher")] | ||
| #[derive(Clone)] | ||
| pub struct DefaultHasher { | ||
| inner: <RandomState as BuildHasher>::Hasher, | ||
| } | ||
|
|
||
| #[cfg(feature = "default-hasher")] | ||
| macro_rules! forward_writes { | ||
| ($( $write:ident ( $ty:ty ) , )*) => {$( | ||
| #[inline(always)] | ||
| fn $write(&mut self, arg: $ty) { | ||
| self.inner.$write(arg); | ||
| } | ||
| )*} | ||
| } | ||
|
|
||
| #[cfg(feature = "default-hasher")] | ||
| impl Hasher for DefaultHasher { | ||
| forward_writes! { | ||
| write(&[u8]), | ||
| write_u8(u8), | ||
| write_u16(u16), | ||
| write_u32(u32), | ||
| write_u64(u64), | ||
| write_u128(u128), | ||
| write_usize(usize), | ||
| write_i8(i8), | ||
| write_i16(i16), | ||
| write_i32(i32), | ||
| write_i64(i64), | ||
| write_i128(i128), | ||
| write_isize(isize), | ||
| } | ||
|
|
||
cuviper marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // feature(hasher_prefixfree_extras) | ||
| #[cfg(feature = "nightly")] | ||
| forward_writes! { | ||
| write_length_prefix(usize), | ||
| write_str(&str), | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| fn finish(&self) -> u64 { | ||
| self.inner.finish() | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is it really necessary for this to implement
Clone? I don't think it every makes sense to clone aHasher.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.
It's probably not necessary, but FWIW both
FoldHasherandstd::hash::DefaultHasherdo implementClone.(
stdalso implementsDebugandDefault, butFoldHasherdoes 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.
stdaddedClonein rust-lang/rust#42799, without much discussion.