Board cannot be the key to a HashMap
Closed this issue · 4 comments
I want to use a board state (represented by the Board
struct in this library) as a key to a HashMap
. This is for a chess engine I am writing for fun.
std::collections::Hashmap
requires that its key be Eq
and Hash
. Both should be doable, yet are not in this library. Checking the struct definition and cross-referencing with cargo doc --open
in my project reveals that the following:
- the only type which needs
Eq
andHash
as well isBitboard
Color
, andSquare
are alreadyHash
andEq
CastleRights
hasHash
, but noEq
(onlyPartialEq
)
As Bitboard
is just a wrapper around a u64
, it seems as simple as adding Hash, Eq
into the #[derive]
. Once that is done, it is probably a similar matter for Board
and CastleRights
.
To-do List / Summary (in no particular order)
-
Hash
forBitboard
-
Eq
forBitboard
-
Hash
forBoard
-
Eq
forCastleRights
-
Eq
forBoard
@jordanbray If I understand this correctly, Bitboard
and CastleRights
would just #[derive(Hash, Eq)]
, while Board
would #[derive(Eq)]
and have an impl Hash
that just returns self.hash
?
CacheTable
has pretty strict requirements (I consider Copy
"strict" as it means only "lightweight" types should be used) and I would be more comfortable using the Rust standard HashMap
.
@jordanbray PR #45 ready for review.