impl Hash for IndexSet, IndexMap
Closed this issue · 4 comments
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?
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(?)
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.
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.
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