Skip to content

impl Hash for IndexSet, IndexMap #67

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
alexheretic opened this issue Feb 26, 2018 · 4 comments
Closed

impl Hash for IndexSet, IndexMap #67

alexheretic opened this issue Feb 26, 2018 · 4 comments

Comments

@alexheretic
Copy link

alexheretic commented Feb 26, 2018

I think it would be useful for IndexSet, like Vec, to implement Hash. Technically there's no reason IndexMap couldn't either, though I'm not sure how useful it would be practically.

It should be a pretty simple addition, are there downsides?

@bluss
Copy link
Member

bluss commented Feb 26, 2018

A hash and equality combination that is consistent needs to be present. I doubt we can or want to do that, because we also want eq rules to be the same as for hashmap(?)

@alexheretic
Copy link
Author

Yep it's one or the other. I hadn't thought about wanting equality to disregard order. I'd have expected otherwise but perhaps it's simpler this way.

Thanks for the clarification.

@cuviper
Copy link
Member

cuviper commented Feb 26, 2018

The open PR rust-lang/rust#48366 is proposing Hash for the standard HashMap and HashSet, using a commutative operation to combine item hashes. Currently that's just wrapping_add, but it sounds like they want to explore stronger options.

@cuviper
Copy link
Member

cuviper commented Jun 25, 2024

I've been thinking about reintroducing ordermap as a newtype wrapper that does consider the order for PartialEq and Eq, also adding Hash, PartialOrd, and Ord, and now I've published that:
https://crates.io/crates/ordermap/0.5.0

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

3 participants