Skip to content

Implement Hash for collections #59

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

Closed
StevenDoesStuffs opened this issue Apr 6, 2019 · 2 comments
Closed

Implement Hash for collections #59

StevenDoesStuffs opened this issue Apr 6, 2019 · 2 comments

Comments

@StevenDoesStuffs
Copy link

Is it possible to implement Hash on the hashmap or hashset?
I know that rust stdlib doesn't do this for security reasons. See rust-lang/rust#21182
But as it seems like the goal of this library isn't as focused on security (y'all are using fxhash) as much the stdlib HashSet is, that shouldn't be an issue.

@Amanieu
Copy link
Member

Amanieu commented Apr 6, 2019

Unfortunately this is not possible because the ordering of the elements in a HashMap is non-deterministic but the hash value depends on the ordering. This means that two HashMaps with the same contents may have different hashes because the elements are in a different order internally.

@Amanieu Amanieu closed this as completed Apr 6, 2019
@StevenDoesStuffs
Copy link
Author

StevenDoesStuffs commented Apr 7, 2019

Actually, you can use a commutative operator to put together the hash of the hashmap given the hashes of the keys and values. I know that other languages do this, so it's definitely not impossible.
Would you like me to give an example implementation?
rust-lang/rust#21182 (comment)
For those not concerned with DDoS attacks with our hashmaps and hashsets, security concerns aren't an issue at all. Of course, mixing for hashmaps will be a bit problematic as you have to choose to hash or not hash the values.

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

No branches or pull requests

2 participants