-
Notifications
You must be signed in to change notification settings - Fork 18
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
Broken hash function #15
Comments
A possible implementation is based on taking the hash of the (uncompressed) output of |
The question is should or should NOT be the such hashes the same? >>> from intbitset import intbitset
>>> a = intbitset([50,60,100], trailing_bits=False)
>>> b = intbitset([50,60,100], trailing_bits=True)
>>> hash(a) == hash(b)
? |
I believe they should be really different. Having The current issue I am having with the implementation I found so far is that the hash of an infinite intbitset from which I remove and then add a bit in the middle is different from the hash of the original intbitset which is not good, since they are semantically identical (albeit they might have some differences in the way they have allocated memory) |
"Can you compare to infinities?" |
Sure :) |
Simple answer: raise exception I would rather see
It's not broken ... it should not have been implemented in first place. |
Read it as: buggy! There's no problem in having a hash function for intbitset. Simply the current implementation has a bug. An intbiset is indeed mutable, but, is more similar to a string (from a data-perspective), since it is simply a container of bits, not of pointers. So as soon as you alter a bit, you obtain a different intbitset, and therefore hash. So it is currently (minus the hash-bug) possible to retrieve in a predictable way the value of |
Is there a use-case for it? Do you really want to make hash on large byte arrays (5MB+)? |
The use cases are the same of frozenset. It's a generic datatype. Who knows the future use-cases. Let me just fix this hashing functions 😜 |
Anyway, I like your proposal for the frozenintbitset. That's probably more clean. and can be the subject of another ticket... |
@jirikuncar wrote
I agree. Either we are hashable and immutable or we are mutable and not hashable and IMHO anything else is an oddity. |
The text was updated successfully, but these errors were encountered: