-
Notifications
You must be signed in to change notification settings - Fork 13.9k
docs: std::hash::Hash should ensure prefix-free data
#89438
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -153,9 +153,19 @@ mod sip; | |
| /// Thankfully, you won't need to worry about upholding this property when | ||
| /// deriving both [`Eq`] and `Hash` with `#[derive(PartialEq, Eq, Hash)]`. | ||
| /// | ||
| /// ## Prefix collisions | ||
| /// | ||
| /// Implementations of `hash` should ensure that the data they | ||
| /// pass to the `Hasher` are prefix-free. That is, different concatenations | ||
|
||
| /// of the same data should not produce the same output. | ||
| /// For example, the standard implementation of [`Hash` for `&str`][impl] passes an extra | ||
| /// `0xFF` byte to the `Hasher` so that the values `("ab", "c")` and `("a", | ||
| /// "bc")` hash differently. | ||
| /// | ||
| /// [`HashMap`]: ../../std/collections/struct.HashMap.html | ||
| /// [`HashSet`]: ../../std/collections/struct.HashSet.html | ||
| /// [`hash`]: Hash::hash | ||
| /// [impl]: ../../std/primitive.str.html#impl-Hash | ||
| #[stable(feature = "rust1", since = "1.0.0")] | ||
| #[rustc_diagnostic_item = "Hash"] | ||
| pub trait Hash { | ||
|
|
||
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.
Thinking more about this... "Collision" isn't the right term, here, is it?
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 not but I can't think of a better word to use.