Skip to content
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

added hash #1118

Closed
wants to merge 1 commit into from
Closed

added hash #1118

wants to merge 1 commit into from

Conversation

eyalk11
Copy link

@eyalk11 eyalk11 commented Oct 27, 2024

Added hash to Board class

self.fullmove_number == board.fullmove_number and
type(self).uci_variant == type(board).uci_variant and
self._transposition_key() == board._transposition_key())
return hash(self) == hash(board)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hash(self) == hash(board) does not imply self equals board (there can be hash collisions).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure I understand the claim. Are you claiming the hash is weak? Because hash collisions are negligible.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe for your use case.

But this is a general purpose library. So we shouldn't assume that we will only ever see 2^32 positions (at which point collisions are likely even for strong 64 bit hashes), or even that inputs aren't specifically chosen by an adversary.

@niklasf
Copy link
Owner

niklasf commented Oct 30, 2024

From https://docs.python.org/3/reference/datamodel.html#object.__hash__:

If a class defines mutable objects and implements an __eq__() method, it should not implement __hash__(), since the implementation of hashable collections requires that a key’s hash value is immutable (if the object’s hash value changes, it will be in the wrong hash bucket).

@niklasf niklasf closed this Oct 30, 2024
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

Successfully merging this pull request may close these issues.

2 participants