I'm a bit confused as to how I should impl Hash on this struct? I Because I thought it's the hash that determines whether something is unique, so should my equality check be included in the hashing somehow?
Looking for some guidance on how Hash and Eq work together.
The hash is only ever used as a pre-check, and then the actual determination is made with ==: It’s ok for two objects that aren’t equal to have the same hash value, but if A == B, then both A and Bmust have the same hash value.
In this case, you could include self.piece.0 in the hash calculation, but I’m not sure about anything else— it depends on what side::from(other.piece.1).to_opposite().to_usize() is actually calculating.
Ah okay, sounds like just the piece.0 should be hashed, yeah
So I'm implementing an algorithm that checks for all possible placements and orientations of a piece. Some pieces are symmetrical though, so if a piece is rotated twice (that is to say it is upside down) and it has no effect on the outcome of next then there is no point including it again in the list (hashset).
I think the simplest solution is to have a "canonical" version of PossibilityReport where piece is transformed to the "minimum Side". Then you can eq/hash as normal.
Just derive Eq, Hash. Create a key function which creates a PossibilityReport that is equal when it should be. Then populate a HashMap using map.insert(item.key(), item()). At this point, you may decide to create a different struct for the key for flexibility.