jordanbray / chess

A rust library to manage chess move generation
https://jordanbray.github.io/chess/
MIT License
243 stars 55 forks source link

Hash eq board #45

Closed Nicholas-Baron closed 3 years ago

Nicholas-Baron commented 3 years ago

Solves #44

This PR makes Board possible to use as the key of a standard Rust HashMap. Most of the changes are additions to #[derive] attribute for the types.

Of note is the impl Hash for Board. The hash function does not return its result and instead has a &mut Hasher parameter to hold the state of the hash. The current solution is to only hash self.hash. This is faster than the #[derive], as it is only one field, but I do not know the implications of using a hash of a hash.

jordanbray commented 3 years ago

I'll look over this tonight I think. Nothing looks crazy to me off hand. There's no reason to believe hashing the hash is going to be a problem, other than a performance hit. I do wish there was a better way, but I don't know of one off-hand.

Nicholas-Baron commented 3 years ago

@jordanbray Are there any comments from your review that I should implement?

jordanbray commented 3 years ago

Sorry for the delay. This all looks good to me. I ran some performance tests just to be sure nothing funky happened, and it didn't.