8000 Add __hash__ on data types by m-burst · Pull Request #458 · evhub/coconut · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add __hash__ on data types #458

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

Merged
merged 1 commit into from
Nov 9, 2018
Merged

Add __hash__ on data types #458

merged 1 commit into from
Nov 9, 2018

Conversation

m-burst
Copy link
Contributor
@m-burst m-burst commented Nov 8, 2018

The added implementation XORs the tuple.__hash__ of the data object with the hash of the class. This should help to avoid collisions between instances of different data types with identical members.

Also added a test which ensures that:

  • hash of a data type instance can be computed;
  • hashes of instances of different data types with same data differ;
  • hash of a data type instance differs from hash of a plain tuple.

Fixes #446.

@evhub
Copy link
Owner
evhub commented Nov 9, 2018

@m-burst This looks great; thanks a lot! Can you also add a test to make sure that the hash is in fact the same for identical data types? It's just nice to have a test both for the positive case and for the negative case.

@evhub evhub added this to the v1.4.1 milestone Nov 9, 2018
The added implementation XORs the `tuple.__hash__` of the data object
with the hash of the class.  This should help to avoid collisions
between instances of different data types with identical members.

Also added a test which ensures that:
* hash of a data type instance can be computed;
* hashes of instances of different data types with same data differ;
* hash of a data type instance differs from hash of a plain tuple.

Fixes #446.
@m-burst
Copy link
Contributor Author
m-burst commented Nov 9, 2018

@evhub Added a simple positive test case.

@evhub evhub added the resolved label Nov 9, 2018
@evhub evhub closed this Nov 9, 2018
@evhub evhub reopened this Nov 9, 2018
@evhub evhub merged commit c607dad into evhub:develop Nov 9, 2018
@m-burst m-burst deleted the data-hash branch November 9, 2018 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0